TKutal TKutal - 1 year ago 101
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

value. Any help will be appreciated. Thank you.


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 Source

Please check in this way

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

Hope this help.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download