iphone - casting object of type id to to an unknown type at runtime -


i have method takes string name of entity in sqlite database trying streamline use little repeating code possible.

here have entity id trying set require object type in readiness make call insert row.

problem when make call nsentitydescription entity still of class id

  id entity;  if ([entityname isequaltostring:@"yadda yadda"]) {      entity = [entityyadda class]; } else if ([entityname isequaltostring:@"blah blah"]) {      entity = [entityblah class]; } else if ([entityname isequaltostring:@"foobar"]) {      entity = [entityfoobar class]; }  (int x=0; x<[data count]; x++) {      entity = [nsentitydescription insertnewobjectforentityforname:entityname inmanagedobjectcontext:context]; 

where going wrong?

thanks

i have 7 different entities identical fields trying dynamically assign required entity class 'entity' in loop have 1 line using nsentitydescription property settings.

well, you've had thought of "why not 1 entity flag field denoting type?", , excellent question, , recommend going route.

if, reason, cannot, declare identical fields in protocol, , declare these 7 entities conform same protocol. in method, type declaration (instead of id): nsmanagedobject<mycustomprotocol> *.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -