Warning 1: I am following a tutorial to create an app and I need to use srandom(time(NULL)). I looked it up on the internet and found that arc4random might be able to solve this problem, but there is not enough information for me to find out how. The warning indicates -
'implicit conversion loses integer precision: 'time_t' (aka 'long') to 'unsigned int'
Here is my code where I have used srandom.
- (void) shuffle {
NSMutableArray *validMoves = [[NSMutableArray alloc] init];
srandom(time(NULL)); // warning is here
for( int i=0; i<SHUFFLE_NUMBER; i++){
[validMoves removeAllObjects];
Warning 2
The warning tells me: 'Values of type "NSInteger" should not be used as format arguments; add an explicit cast to "long" instead.'
Could I know whether there is any way to fix this warning.... or do I definetely have to make %d %ld with 'long'?
if ([prefs boolForKey:@"Refresh"] == TRUE) {
countmove = 0;
thetime = 0;
if (timer != nil) {
[timer invalidate];
timer = nil;
}
NSString *Pic = [NSString stringWithFormat:@"image%d.png", [prefs integerForKey:@"PuzzlePicture"]];
[self initPuzzle:Pic];
The compiler can make these format changes for you, so there's no reason not to make them.
Remember that the underlying type of NSInteger and NSUInteger is different on 32 bit and 64 bit processors (intentionally), so you can't have one format that works correctly to print an NSInteger both on 32 and 64 bit (except you can try z which is intended for size_t).