objective-c - 比较 NSString 和有关 NSNumber 的警告

标签 objective-c ios cocoa-touch comparison compiler-warnings

有时 JSON 从获取数据的数据库返回 (null),因此我会检查它是否已返回该 (null)

else if (NSOrderedSame == [[clubsArray objectAtIndex:indexPath.row] compare:@"(null)"] )

但是 Xcode 警告我

Incompatible Objective-C types 'struct NSString *', expected 'struct NSNumber *' when passing argument 1 of 'compare:' from distinct Objective-C type

我将 NSString 添加到该数组中,因此我很困惑为什么它谈论结构。

NSString *clubNameReturned = [message objectForKey:@"clubname"];
[clubsArray addObject:clubNameReturned];

有人能解释一下这里发生的事情吗?

代码按照我的预期执行,但我不想做一些不正确的事情。

最佳答案

JSON 不返回“(null)”字符串。此字符串“(null)”仅是当您 NSLog 空单例对象时控制台上显示的内容(它是 description 表示形式)。

[NSNull null] 进行比较,即 a singleton especially used to store something that represent the null/nil value on containers .

关于objective-c - 比较 NSString 和有关 NSNumber 的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6416335/

相关文章:

objective-c - 如何更改 cocoa 应用程序中的 View Controller ?

iphone - 核心数据/ cocoa : @distinctUnionOfObjects not returning a usable NSArray*

ios - 检测 View Controller 何时从弹出窗口出现

ios - 在绘图应用程序 Swift 3 中使用 UndoManager 实现重做和撤消

objective-c - 我需要什么样的算法?

触摸屏幕时 ios 应用程序崩溃

ios - 给MKMapView添加注解时出现EXC_BAD_ACCESS错误

ios - 禁用在屏幕特定区域的 uipageviewcontroller 上滑动

ios - forceTouchCapability 返回零

ios - NSDateFormatter 意外调整时间的问题