iphone - NSDictionary Error Handling -
i creating application don't know how handle error when there no value given entry in nsdictionary. here code have currently:
nsdictionary *entry = [self entries][indexpath.row]; nsdictionary *text = [self entries][indexpath.row]; nsstring *user = entry[@"user"][@"full_name"]; nsstring *caption = text[@"caption"][@"text"]; if (caption != nil && entry != [nsnull null] && text != nil && caption != [nsnull null]) { rnblurmodalview *modal = [[rnblurmodalview alloc] initwithviewcontroller:self title:user message:caption]; [modal show]; }
here error response receive when tap on cell without caption:
2013-08-08 02:36:57.871 floadt[5566:c07] -[nsnull objectforkeyedsubscript:]: unrecognized selector sent instance 0x310b678 2013-08-08 02:36:57.872 floadt[5566:c07] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[nsnull objectforkeyedsubscript:]: unrecognized selector sent instance 0x310b678' *** first throw call stack: (0x2fda012 0x260be7e 0x30654bd 0x2fc9bbc 0x2fc994e 0x5606b 0x1c7a42f 0x1c8c182 0x1c8c394 0x261f705 0x188693c 0x18869ac 0x261f705 0x188693c 0x18869ac 0x1a401d3 0x2fa2afe 0x2fa2a3d 0x2f807c2 0x2f7ff44 0x2f7fe1b 0x2bb77e3 0x2bb7668 0x1778ffc 0x2d2d 0x2c55) libc++abi.dylib: terminate called throwing exception
not clear why entry
, text
same thing. typo causing issues:
nsdictionary *entry = [self entries][indexpath.row]; nsdictionary *text = [self entries][indexpath.row];
then, should use isequal
equality checks (even if prevent getting bad habits) , check obtained values (you don't check user
):
if (![user isequal:[nsnull null]] && ![caption isequal:[nsnull null]]) {
your current checks redundant - need check things before use them, not afterwards. checking entry
, text
must done earlier. check user
, caption
.
Comments
Post a Comment