我正在使用示例here。如果密钥没有值,我的应用程序将在控制台中返回-[NSCFArray insertObject:atIndex:]: attempt to insert nil
,并且我的窗口不会显示。我怎么能预先检查以确保不会发生这种情况?
答案 0 :(得分:1)
测试对象指针是否为nil
:
if (theObject != nil) {
[myArray insertObject:theObject atIndex:idx];
} else {
//The pointer is nil. This probably means the JSON framework gave you an error object (assuming you enabled it to), in which case, now's probably the time to present it.
if (error != nil)
[NSApp presentError:error];
}