I am going through a former employees code and about 20 of these warnings show up:
Values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead
one part of the code where this arises is:
NSUInteger Length;
With:
- (NSString *) description {
// If no value was given, display type
if([Value length] == 0)
{
NSString *type = @"";
switch (Type) {
case DTCompType_Year: type = @"year";
break;
case DTCompType_Month: type = @"month";
break;
case DTCompType_Day: type = @"day";
break;
case DTCompType_Hour: type = @"hour";
break;
case DTCompType_Minute: type = @"minute";
break;
case DTCompType_Second: type = @"second";
break;
case DTCompType_Meridiem: type = @"meridiem";
break;
case DTCompType_MonthName: type = @"month_name";
break;
case DTCompType_DayOfTheWeek: type = @"day_of_the_week";
break;
case DTCompType_Undefined: type = @"undefined";
break;
}
return Length == 0 ? [NSString stringWithFormat:@"[%@]", type] :
[NSString stringWithFormat:@"[%@:%i]", type, Length];
}
No where in apples documentation can I find %i
I have never worked with Objective-C before, and now I have to update this app. I understand that this needs to become an unsigned long, but I don't want to start changing things without knowing why. The app works just fine as is, so are there any inherent consequences for changing these to unsigned long? or even changing the format specifier from %i
to %lu
?
From what I've read, it could be a matter of the platform. (32-bit vs 64-bit)
This was developed for an iPad 2 in iOS7, and we just upgraded the SDK to iOS8.
I found this post: NSUInteger should not be used in format strings? which has given me some guidance, but I need more clarification.