Core data not saving my data

前端 未结 2 497
名媛妹妹
名媛妹妹 2021-01-20 21:45

I\'m using core data to save some integer (rate) and then I call save in the context:

HeartRateBeat * beat = [HeartRateBeat heartRateWithHeartRate:rate
              


        
2条回答
  •  北海茫月
    2021-01-20 22:28

    I get the same problem but I think its just because, I assume, like me you are just stopping the app through xcode and not actually closing it down. I use this code to force a write. Im using a UIManagedDocument, shared through appdelegate, rather than setting everything up manually.

    NSError *error = nil;
    
    if (![self.managedObjectContext save:&error]) {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }
    
    [[AppDelegate sharedAppDelegate].userDatabase saveToURL:[AppDelegate sharedAppDelegate].userDatabase.fileURL forSaveOperation:UIDocumentSaveForOverwriting completionHandler:nil];
    

提交回复
热议问题