ios programming - Data argument not used by format string

后端 未结 2 1634
刺人心
刺人心 2021-01-05 03:52

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

- (void)pickerView:(UIPickerView *)thePickerView didSelectR         


        
相关标签:
2条回答
  • 2021-01-05 04:47
    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.

    0 讨论(0)
  • 2021-01-05 04:49

    Answer from @debuggerman is absolutely correct. But you can improve your code if you use [defaults setObject:colour forKey:@"colour”]; instead of [defaults setObject:(colour) forKey:@"colour"];

    Note that I removed the parentheses for object colour.

    0 讨论(0)
提交回复
热议问题