Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To check if an attribute exists at runtime on a NSManagedObject subclass

How to check if an attribute exists for a particular entity at runtime. I will implement a property named dateAddStamp, but not all entities have this attribute. This class will serve as a base for other entity's classes... So I want to check at runtime If I can call [self setPrimitiveValue:xxx forKey:xxx] or not... Thanks.

like image 446
the Reverend Avatar asked Dec 06 '11 23:12

the Reverend


2 Answers

in swift

 let hasFoo =  myObject.entity.propertiesByName.keys.contains("foo")
like image 176
techloverr Avatar answered Sep 19 '22 08:09

techloverr


BOOL hasFoo = [[myObject.entity propertiesByName] objectForKey:@"foo"] != nil;
like image 22
omz Avatar answered Sep 23 '22 08:09

omz