Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Intermittent Crash: - setObjectForKey: Object cannot be nil (key:ref_id)

Intermittent Crash: - setObjectForKey: Object cannot be nil.(key: ref_id)


ref_id object is string/number in the JSON response.

Same code works most of the time. But sometime it crashes (~less than 5%).


NSDictionary *udfDict = nil;

if (data) {

if ([data length] > 0) {

udfDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&serializationError];

}

}


if (udfDict) {

NSString *transactionreason;

NSString *refId;

if (![CustomUtilities isEmptyOrNull:udfDict[@"ref_id"]]) {

refId = udfDict[@"ref_id"];

[dict setObject:refId forKey:@"ref_id"];

}


Concern: If its not able to downcast from number to string, the code should break all the time.But thats not the case.The crash is intermittent and only code breaks for ~5% occurances.

iPhone 6s, iOS 9.2, Xcode7.2

Posted on Feb 5, 2016 1:38 AM

Reply

There are no replies.

Intermittent Crash: - setObjectForKey: Object cannot be nil (key:ref_id)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.