ios - How to use NSManagedObject without adding it to db? -
i'm having class inherits nsmanagedobject generated using db model:
// .h @interface sketch : nsmanagedobject @property (nonatomic, retain) nsdate * added; @property (nonatomic, retain) nsstring * board; @property (nonatomic, retain) nsstring * filepath; @property (nonatomic, retain) nsstring * title; @property (nonatomic, retain) nsstring * filename; @end // .m @implementation sketch @dynamic added; @dynamic board; @dynamic filepath; @dynamic title; @dynamic filename; @end i'm using class instances in uitableview. need add instances not stored in db (just show them in list):
sketch sketch = [[sketch alloc] init]; but when trying set instance properties
sketch.title = @"test title"; i'm getting exception:
-[sketch settitle:]: unrecognized selector sent instance 0x7ff112c13e30 does mean have to create instance adding them managed context (even if i'm not going store them)?
[nsentitydescription insertnewobjectforentityforname:sketch_entity inmanagedobjectcontext:context];
no, can create instances of nsmanagedobject subclasses , add them managed object context later (while i'd suggest not do so). have issue sketch object, not nsmanagedobject , nsmanagedobjectcontext.
the thing should create this:
nsmanagedobjectcontext *moc = ... // managed object context nsentitydescription *entity = [nsentitydescription entityforname:@"sketch" inmanagedobjectcontext:moc]; // note nil context sketch *unassociatedobject = (sketch *)[[nsmanagedobject alloc] initwithentity:entity insertintomanagedobjectcontext:nil]; for more details see this answer.
Comments
Post a Comment