1
votes
static id SLRandomValueFromArray(NSArray *array) {
    if ([array count] == 0) {
        return nil;
    }

    return [array objectAtIndex:(NSUInteger)arc4random_uniform([array count])]; // WARNING HERE
}

The warning says

Implicit conversion loses integer precision: 'NSUInteger' (aka 'unsigned long') to 'u_int32_t' (aka 'unsigned int')

I've never come across this warning before and not really sure how to resolve this with Xcode 7 and iOS 8

1

1 Answers

1
votes

Change your code to this

[array objectAtIndex:arc4random_uniform((u_int32_t)[array count])]

Reason:

This is the arc4random_uniform in stdlib.h,its input is u_int32_t

u_int32_t arc4random_uniform(u_int32_t /*upper_bound*/)

But the [array count] return NSUInteger,so you need to cast