ios - Issue with Coredata update -


i'm trying update currency abbreviations in coredata function.

- (void)updatecurrencies {     nsmanagedobjectcontext *managedobjectcontext = self.managedobjectcontext;     if (managedobjectcontext != nil) {          nsfetchrequest *request = [[nsfetchrequest alloc] init];         [request setentity:[nsentitydescription entityforname:@"transaction" inmanagedobjectcontext:managedobjectcontext]];          nserror *error = nil;         nsarray *results = [managedobjectcontext executefetchrequest:request error:&error];         nslog(@"number of data : %lu", (unsigned long)[results count]);          (int = 0; < [results count]; i++) {             transaction* t = [results objectatindex:0];             nslog(@"currency: %@", t.currency);             if ([t.currency isequaltostring:@"can"]) {                 t.currency = @"cad";                 nslog(@"new currency set.");             }             [self savecontext];         }     } } 

i call function in didfinishlaunchingwithoptions. now, log inform me t.currency has been updated cad. when retrieve data again in homeviewcontroller , log currency, can. code in homeviewcontroller,

nsfetchrequest *request = [[nsfetchrequest alloc] init]; nsentitydescription *transaction = [nsentitydescription entityforname:@"transaction" inmanagedobjectcontext:_managedobjectcontext]; [request setentity:transaction]; request.predicate = [nspredicate predicatewithformat:@"transactiontouser = %@", [self.content objectatindex:i]];  nssortdescriptor *descriptor = [[nssortdescriptor alloc] initwithkey:@"postdate" ascending:no]; nsarray *descriptors = [[nsarray alloc] initwithobjects:descriptor, nil]; [request setsortdescriptors:descriptors];  nserror *error = nil; nsmutablearray *mutableresult = [[_managedobjectcontext executefetchrequest:request error:&error] mutablecopy]; if (mutableresult == nil) {     //handle error }  (int k = 0; k < [mutableresult count]; k++) {     transaction *t = [mutableresult objectatindex:k];     nslog(@"currency xx: %@", t.currency); } 

what doing wrong? appreciated. thanks.

fixed different loop.

for (transaction *t in results)  {     ... } 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -