nsmanagedobject - Save multiple attributes to same core data entity -
i first time user of core data , trying learn core data.
for start employee example 2 attributes. 1. name 2. salary
now done necessary things needed loading data db. values saved before.
but problem able save 1 attribute of employee table.for first time saved name of employee. when got success in that, try save name salary got [nsmanagedobject setsalary:]: unrecognized selector sent instance 0x7472d80 exception.
here code.
- (ibaction)setbtntouched:(id)sender { employee *newemp = [nsentitydescription insertnewobjectforentityforname:@"employee" inmanagedobjectcontext:context]; [newemp setname:self.textfieldname.text]; [emp addobject:newemp]; /* code added after success in saving employee name.*/ //[newemp setsalary:self.textfieldsal.text]; //[emp addobject:newemp]; */ bool issaved = [context save:nil]; nslog(@"is saved %d",issaved); nslog(@"emp :%@",emp); } i dont understand went wrong because both attributes of same entity.
please write thread.
edited: screen shot
regards, paggyyy123
make sure nsmanagedobject subclass contains correct attribute name accessor.
// employee.m @dynamic salary also, note adding new employee array emp twice. these 2 identical once attributes complete.
Comments
Post a Comment