Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios programming - Data argument not used by format string

I get a Data argument not used by format string error when I run the following code:

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

NSString *colour = ([colourArray objectAtIndex:row]);

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

[defaults setObject:(colour) forKey:@"colour"];

NSLog(@"NSString =", colour);
NSLog(@"NSUserDefaults =", [defaults objectForKey:@"colour"]);

}

I get the error on both NSLog lines. Also, here is what the log says:

2011-10-25 09:01:50.260 Random[35636:b303] NSString =
2011-10-25 09:01:50.260 Random[35636:b303] NSUserDefaults =

Thank you, Arthur

like image 926
gadgetmo Avatar asked Oct 25 '11 08:10

gadgetmo


1 Answers

NSLog(@"NSString = ", colour);    
NSLog(@"NSUserDefaults =", [defaults objectForKey:@"colour"]);

Is problematic

Should be

NSLog(@"NSString = %@", colour);
NSLog(@"NSUserDefaults = %@", [defaults objectForKey:@"colour"]);

The format specifier in this case is the %@ which is used to print an object. To print numbers you'd use something like %d. See complete documentation here.

like image 154
zakishaheen Avatar answered Nov 06 '22 07:11

zakishaheen