2 comparison cocoa-touch objective-c compiler-warnings ios
有时JSON会(null)从数据库中返回数据,因此我会检查它是否返回了数据(null).
else if (NSOrderedSame == [[clubsArray objectAtIndex:indexPath.row] compare:@"(null)"] )
Run Code Online (Sandbox Code Playgroud)
但Xcode警告我
不兼容的Objective-C类型'struct NSString*',当从不同的Objective-C类型传递'compare:'的参数1时,预期'struct NSNumber*'
我将NSStrings 添加到该数组中,所以我很困惑为什么它在讨论结构.
NSString *clubNameReturned = [message objectForKey:@"clubname"];
[clubsArray addObject:clubNameReturned];
Run Code Online (Sandbox Code Playgroud)
有人能够对这里发生的事情有所了解吗?
代码按照我的预期执行,但我不想做一些不正确的事情.
JSON不返回"(null)"字符串.此字符串"(null)"仅是NSLog空单例对象(它的description表示)时控制台上显示的字符串.
针对比较[NSNull null]代替,这是特别用来存储表示对集装箱空/空值的东西单身.