core data - Creating entity with Magical Record only in OSX (+entityForName: could not locate an entity named '(null)' in this model.) -
hi having problem creating entitys magicalrecord in osx, create model , nsmanagagedsubclasses , on. when run code in applicationdidfinishlaunching(i using magicalrecord 2.2):
[magicalrecord setupcoredatastack]; person * person = [person mr_createentity]; person.name = @"alex";
i in log:
2013-10-06 18:01:54.320 testmagicalrecord[7554:303] +[nsmanagedobjectcontext(magicalrecord) mr_contextwithstorecoordinator:](0x7fff71a96238) -> created context unnamed 2013-10-06 18:01:54.321 testmagicalrecord[7554:303] +[nsmanagedobjectcontext(magicalrecord) mr_setrootsavingcontext:](0x7fff71a96238) set root saving context: <nsmanagedobjectcontext: 0x101924d00> 2013-10-06 18:01:54.321 testmagicalrecord[7554:303] +[nsmanagedobjectcontext(magicalrecord) mr_newmainqueuecontext](0x7fff71a96238) created main queue context: <nsmanagedobjectcontext: 0x1001564a0> 2013-10-06 18:01:54.321 testmagicalrecord[7554:303] +[nsmanagedobjectcontext(magicalrecord) mr_setdefaultcontext:](0x7fff71a96238) set default context: <nsmanagedobjectcontext: 0x1001564a0> 2013-10-06 18:01:54.322 testmagicalrecord[7554:303] +entityforname: not locate entity named '(null)' in model.
when run same code in ios project runs no problems, have been trying find sample code osx no luck, should different?
the mac sample code in magical record github repo contain project there way run other resources?
i bet simple solution cant find in docs/so work.
as found out in mean time, bug in development branch of magical record.
in 2.2 version of development branch, mr_createentity
uses following method determine entity name of object should created:
+ (nsstring *) mr_bestguessatanentityname { if ([self respondstoselector:@selector(entityname)]) { return [self performselector:@selector(entityname)]; } return nsstringfromclass(self); }
but (at least on os x 10.8), nsobject
responds entityname
, , invoking method returns nil
. not find documentation on this, might internal undocumented method.
but effect mr_bestguessatanentityname
returns nil
, , therefore
+ (id) mr_createincontext:(nsmanagedobjectcontext *)context { return [nsentitydescription insertnewobjectforentityforname:[self mr_bestguessatanentityname] inmanagedobjectcontext:context]; }
fails error message
+entityforname: not locate entity named '(null)' in model.
so magical record bug, , worth reporting maintainers. bug occurs on os x, because nsobject
(or nsmanagedobject
) not respond entityname
on ios.
Comments
Post a Comment