Search code examples
iphonepropertiesnsloguidevice

Problems with UIDevice properties and NSLog


I've been trying to log device parameters using [[UIDevice currentDevice] ...] and NSLog. I always get the same warning despite trying different ways to go about it.

The warning I get is:

Passing argument 1 of 'NSLog' from incompatible pointer type

Here are all my attempts:

1:

NSString *UDID = [[UIDevice currentDevice] uniqueIdentifier];
    NSString *deviceName = [[UIDevice currentDevice] name];
    NSString *deviceModel = [[UIDevice currentDevice] model];

    NSLog("\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",UDID, deviceName, deviceModel);

2:

NSString *UDID = (NSString*)[[UIDevice currentDevice] uniqueIdentifier];
    NSString *deviceName = (NSString*)[[UIDevice currentDevice] name];
    NSString *deviceModel = (NSString*)[[UIDevice currentDevice] model];

    NSLog("\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",UDID, deviceName, deviceModel);

3:

NSString *UDID = [NSString stringWithFormat:[[UIDevice currentDevice] uniqueIdentifier]];
    NSString *deviceName = [NSString stringWithFormat:[[UIDevice currentDevice] name]];
    NSString *deviceModel = [NSString stringWithFormat:[[UIDevice currentDevice] model]];

    NSLog("\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",UDID, deviceName, deviceModel);

4:

NSLog("\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",[[UIDevice currentDevice] uniqueIdentifier], [[UIDevice currentDevice] name], [[UIDevice currentDevice] model]);

Can anyone help me out? Thanks!


Solution

  • You need to use an NSString as the first argument to NSLog For example

    NSLog(@"\nDevice UDID: %@\nDevice Name: %@\nDevice Mode:%@\n",UDID, deviceName, deviceModel);
    

    Notice the '@' before the start of the string