Reputation: 904
Format specifies type "unsigned long" but the argument has type "int"
I get this error in XCode and no matter what format specifier I put in or if I change to NSInteger, NSUInteger, long or int, still get errors!? How can I fix this?
In
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
I have these lines, in line 2 is the error at @"%lu",(row % max)
NSUInteger max = (NSInteger)[self.calendar maximumRangeOfUnit:NSCalendarUnitHour].length;
[lblDate setText:[NSString stringWithFormat:@"%lu",(row % max)]];
lblDate.textAlignment = NSTextAlignmentRight;
Thanks for help !
Upvotes: 4
Views: 7210
Reputation: 904
ok, seems xcode is happy with %td although it was suggesting something else all the time. Thanks !
Upvotes: 0
Reputation: 211
Change your code to following:
NSUInteger max = (NSInteger)[self.calendar maximumRangeOfUnit:NSCalendarUnitHour].length;
[lblDate setText:[NSString stringWithFormat:@"%d",(int)(row % max)]];
lblDate.textAlignment = NSTextAlignmentRight;
Upvotes: 4
Reputation: 2534
Use a format specifier that matches to the NSUInteger type, like %tu, or cast the result of (row % max) to an int.
Upvotes: 1
Reputation: 5466
For NSInteger
you should use %td
or %tu
for NSUInteger
See this link for more details https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html
Upvotes: 9