This means that NSInteger/NSUInteger are long instead of int. CGFloat is double, not float.
There are many possible compiler warnings and here are the resolutions.
Case 1: Implicit conversion loses integer precision: 'long' to 'int'
Example:
NSInteger row = ...;
int rowWithLineCount = (rows - 1) / 5 ; // compiler warning
NSInteger rowWithLineCount = (rows - 1) / 5 ;
Note: Use NSUInteger if the right hand expression is evaluated to unsigned integer.
Case 2: Implicit conversion loses integer precision: 'NSInteger' (aka 'long') to SomeEnum'
Example:typedef enum {
...
} SomeEnum;
NSInteger someValue;
SomeEnum somefield = someValue; // compiler warning
Solution: Use NS_ENUM
...
};
Case 3: Implicit conversion loses integer precision: 'SomeEnum' (aka 'enum SomeEnum') to int'
Example:typedef NS_OPTIONS(NSUInteger, SomeEnum) {
...
}
SomeEnum somefield;
NSNumber *number = [NSNumber numberWithInt:self.someField]; // compiler warning
NSInteger statusCode = ...;
Solution:
Solution:
NSNumber *number = [NSNumber numberWithLong:self.someField];
Case 4: Values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead
Example:NSInteger statusCode = ...;
NSLog(@"Failed response code:%d", statusCode); // compiler warning
Solution:
NSLog(@"Failed response code:%ld", (long)statusCode);
Note: This applies to %lu string pattern and (unsigned long) casting for NSUInteger as well.
No comments:
Post a Comment