ios - The world of generated NSManagedObjects and a Superclass -


i have several generated nsmanagedobject subclasses. using article created parent class (named qualifier) nsmanagedobject subclasses extend. in way can have class hierarchy without entity hierarchy.

i have problem won't know until runtime subclass need create. have string representing class name. put method in qualifier class creates specific subclass:

+ (instancetype) insertnewobjectfor:(nsstring *) qualifiername intocontext:(nsmanagedobjectcontext *) managedobjectcontext {      nsmanagedobjectmodel *managedobjectmodel = [[managedobjectcontext persistentstorecoordinator] managedobjectmodel];     class qualifierclass = nsclassfromstring(qualifiername);     nsentitydescription *entity = [[managedobjectmodel entitiesbyname] objectforkey:qualifiername];     qualifier *object = [[qualifierclass alloc] initwithentity:entity insertintomanagedobjectcontext:managedobjectcontext];      return(object);  } 

i'm new @ objective c , wanted ask more informed stack exchangers if acceptable way create specific instance?

that's fine, although it's more steps necessary. i'd simplify to:

qualifier *object = [nsentitydescription insertnewobjectforentityforname:qualifiername      inmanagedobjectcontext:context]; 

Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -