Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 关于隐式转换丢失整数精度的警告_Ios_Warnings_Xcode7 - Fatal编程技术网

Ios 关于隐式转换丢失整数精度的警告

Ios 关于隐式转换丢失整数精度的警告,ios,warnings,xcode7,Ios,Warnings,Xcode7,警告说 static id SLRandomValueFromArray(NSArray *array) { if ([array count] == 0) { return nil; } return [array objectAtIndex:(NSUInteger)arc4random_uniform([array count])]; // WARNING HERE } 我以前从未遇到过这个警告,也不知道如何用Xcode 7和iOS 8解决这个问题

警告说

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

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

我以前从未遇到过这个警告,也不知道如何用Xcode 7和iOS 8解决这个问题

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

这是stdlib.h中的
arc4random\u uniform
,其输入为
u\u int32\u t

[array objectAtIndex:arc4random_uniform((u_int32_t)[array count])]
但是
[array count]
返回整数,因此需要强制转换

u_int32_t arc4random_uniform(u_int32_t /*upper_bound*/)