SBJson returning nil causing cocoa window to not show up
I'm using the example here. If there 开发者_如何学Goisn't a value for the key, my application returns -[NSCFArray insertObject:atIndex:]: attempt to insert nil
in the console, and my window doesn't show up. How could I preform a check to make sure this doesn't happen?
Test whether the object pointer is 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];
}
精彩评论