Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Data One to Many Relationship: unrecognized selector sent to instance
    text
    copied!<p>I am having two classes or objects: <code>User</code> and <code>Medicine</code>. Here is my <code>User</code> class:</p> <pre><code>@interface User : NSManagedObject @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) NSSet *medicine; @end @interface User (CoreDataGeneratedAccessors) - (void)addMedicineObject:(Medicine *)value; - (void)removeMedicineObject:(Medicine *)value; - (void)addMedicine:(NSSet *)values; - (void)removeMedicine:(NSSet *)values; @end </code></pre> <p>and then the <code>Medicine</code> class</p> <pre><code>@interface Medicine : NSManagedObject @property (nonatomic, retain) NSString * medName; @property (nonatomic, retain) NSString * medType; @property (nonatomic, retain) Dose *dose; @property (nonatomic, retain) User *user; @end </code></pre> <p>As my interfaces clearly show that user may have multiple medicines. (I am from database background thats why I am interpreting it like this).</p> <p>When I add new object in <code>User</code>, it is easily done, but when I try to add new <code>Medicine</code> for existing object of user, I feel that my Xcode has a deep wish to shoot me at that time (vice versa). </p> <p>Now here is the code that describes what I am doing:</p> <pre><code>Medicine *object = [[self fetchedResultsController] objectAtIndexPath:indexPath]; User *user = [NSEntityDescription insertNewObjectForEntityForName:@"User" inManagedObjectContext:self.managedObjectContext]; if(![self checkUser]) { object.user = user; [user setName:self.userName]; NSLog(@"%@ %@",object, user); self.detailViewController.detailItem = object; } else { Medicine *medicine = [NSEntityDescription insertNewObjectForEntityForName:@"Medicine" inManagedObjectContext:self.managedObjectContext]; user = [self getUser:self.userName]; medicine.medName = object.medName; medicine.medType = object.medType; [medicine setUser:user]; self.detailViewController.detailItem = medicine; } </code></pre> <p>I am having a simple logic: if name entered by user in text field, already exist in DB, then return the <code>User</code> object. Then just add another <code>Medicine</code> record for the same <code>User</code>. Other wise add new <code>User</code> and a <code>Medicine</code> object as well. </p> <p>but I get error at:</p> <pre><code>[medicine setUser:user]; </code></pre> <p>I also tried this one: (as I got it in another question like mine)</p> <pre><code>[user addMedicineObject:medicine]; </code></pre> <p>Now I think that I have to override <code>addMedicineObject</code> method or something else.</p> <p>Oh I forgot the error. I get this error: (the real villain)</p> <pre><code>[__NSArrayM managedObjectContext]: unrecognized selector sent to instance 0x8136bf0 </code></pre> <p>Now any suggestion?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload