ios - Unable to find specific subclass of NSManagedObject -
i'm working on developing app core data. when created instance using:
let entity = nsentitydescription.entityforname("user", inmanagedobjectcontext: appdelegate.managedobjectcontext) let user = user(entity: entity, insertintomanagedobjectcontext: appdelegate.managedobjectcontext)
i got warning in log:
coredata: warning: unable load class named 'user' entity 'user'. class not found, using default nsmanagedobject instead.
how fix it?
and question, how can define instance method in nsmanagedobject subclass?
edit:
i have specified class of entity in following screenshot:
update xcode 7 (final): prepending module name class (as in xcode 6 , beta releases of xcode 7) no longer necessary. apple documentation implementing core data managed object subclasses has been updated accordingly.
the data model inspector has 2 fields "class" , "module" entity:
when create swift managed object subclass entity, "module" field set "current product module", , setting creating instances works both in main application , in unit tests. managed object subclass must not marked @objc(classname)
(this observed in https://stackoverflow.com/a/31288029/1187415).
alternatively, can empty "module" field (it show "none") , mark managed object subclasses @objc(classname)
(this observed in https://stackoverflow.com/a/31287260/1187415).
remark: answer written xcode 6. there changes in various xcode 7 beta releases respect problem. since accepted answer many upvotes , links it, have tried summarize situation current xcode 7 final version.
i did both own "research" , read answers both question , similar question coredata: warning: unable load class named. attribution goes of them, if don't list them specifically!
previous answer xcode 6:
as documented in implementing core data managed object subclasses, have prefix entities class name in class field in model entity inspector name of module, example "myfirstswiftapp.user".
Comments
Post a Comment