iphone - How to use methods from NSManagedObject entity using NSManagedObject -


i using nsmanagedobject save values, not using entity that. because want not limit entities. tried using (oist *)managedobject.entity, not working. how use managedobject theit's this:

oist.h @class file;  @interface oist : nsmanagedobject @property (nonatomic, retain) nsset *files; @end  @interface oist (coredatageneratedaccessors)  - (void)addfilesobject:(file *)value;  file.h @class oist;  @interface file : nsmanagedobject  @property (nonatomic, retain) oist *gist;  @end  - (void)newmanagedobjectwithclassname:(nsstring *)classname forrecords:(nsdictionary *)records {     nsmanagedobject *newmanagedobject = [nsentitydescription insertnewobjectforentityforname:classname inmanagedobjectcontext:[[gpcoredatacontroller sharedinstance] backgroundmanagedobjectcontext]];     [records enumeratekeysandobjectsusingblock:^(id key, id obj, bool *stop) {         [self setvalue:obj forkey:key formanagedobject:newmanagedobject];     }]; }  - (void)setvalue:(id)value forkey:(nsstring *)key formanagedobject:(nsmanagedobject *)managedobject {     file *fileentity = [nsentitydescription insertnewobjectforentityforname:@"file" inmanagedobjectcontext:[[gpcoredatacontroller sharedinstance] backgroundmanagedobjectcontext]];      if ([key isequaltostring:@"files"])     {         nsdictionary *files = (nsdictionary *)value;         (nsstring *key in [files allkeys]) {             nsdictionary *file = [files valueforkey:key];             nslog(@"%@", file[@"filename"]);             [fileentity setvalue:file[@"filename"] forkey:@"filename"];             [fileentity setvalue:file[@"type"] forkey:@"type"];         }     } else if ([key isequaltostring:@"id"])     {         if ([managedobject.entity.name iskindofclass:[oist class]]) {         //here want use oist's method - (void)addfilesobject:(file *)value; how that?         }         [managedobject setvalue:[nsnumber numberwithint:[value integervalue]] forkey:@"gistid"];     } } 

i may misunderstanding question, looks you're hoping cast generically typed (nsmanagedobject *) more typed subclass.

the way check if pointer passed generically in fact instance of subclass this:

if ([managedobject iskindofclass:[oist self]]) {     // managedobject may safely cast oist* } 

you can cast without assignment, this:

[(oist *)managedobject addfiles...]; 

or, proper parentheses, access property (the dot operator has higher precedence cast, need tell compiler want cast first):

((oist *)managedobject).entity 

but think that's less clear reader , potentially more keystrokes explicit assignment cast, i'd recommend:

if ([managedobject iskindofclass:[oist self]]) {    oist *oist = (oist *)managedobject;    [oist addfilesobject:somefilesobject]; } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -