TKutal TKutal - 2 months ago 14
Objective-C Question

Check if an attribute of a CoreData entity is null?

I want to check if the attribute on a core data entity is Null or not. I tried several approaches and went through some questions on SO and surprisingly there were no answer or they didn’t work. The question here mentions all the possible ways to check the attributes value but there are no inputs that work. My app crashes when i try to check the attribute for a

Null
value. Any help will be appreciated. Thank you.

EDIT

NSMutableAttributedString *attrStringNew = [[NSMutableAttributedString alloc] initWithString:[contact valueForKey:@"first_name"]];
[attrString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica Neue" size:10] range:boldedRange];
titleLbl.attributedText = attrStringNew;


So a case where the contact has no first name, my app will crash.

Answer

Please check in this way

if([contact valueForKey:@"first_name"]) 
{ ........code here }
else 
{ //Handle issue here 
}

Hope this help.