0

I am new to Core Data also RestKit.

Since there are some performance issues, I want to use the concurrency technique in ios5. However, when it combined with RestKit, the crashing problem appeared. Here is my crash code:

[[RKObjectManager sharedManager] getObjectsAtPath: HOT_PATH
                                       parameters: params
                                          success:
 ^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    NSManagedObjectContext *newContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
     newContext.parentContext = [self managedContext];
     [newContext performBlock:^{

         Rumor *rumorInOtherContext = (Rumor *)[mappingResult.array lastObject];;
         Rumor *rumor = (Rumor *)[newContext objectWithID:rumorInOtherContext.objectID];

         rumor.updateDate = [NSDate date]; // <- crash at this point.
}];

However, the old version of my code wouldn't crash:

[[RKObjectManager sharedManager] getObjectsAtPath: HOT_PATH
                                       parameters: params
                                          success:
 ^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    Rumor *rumor = (Rumor *)[mappingResult.array lastObject];;
    rumor.updateDate = [NSDate date]; // <- save!
}];

No crash report appeared in console dialog. :(

Is my code correct? Or, are there another approaches to do the same thing?

Ray Shih
  • 933
  • 8
  • 18
  • This is the simplify version of my code, and the later approach will become a performance issue that will eliminate the UX. – Ray Shih Mar 04 '13 at 17:26

1 Answers1

1
  1. What target version of iOS are you using?
  2. What version of RK are you using?

If you are targeting 5.x, you can not use the block-based concurrent programming code for Core Data, or Parent-Child Contexts. (Yes they were incorporated into iOS in 5.x, but it does not work and is unsafe until 6.x)

You may want to look into GCD.

I have had many issues with RK and decided to move away from it, like discussed in this question:

RestKit and saving to CoreData as NSManagedObject

And what is the stacktrace (if you experienced this on a device there WILL be a crash log that you can access from Window->Organizer->Devices) telling you when you crash???

Community
  • 1
  • 1
G. Shearer
  • 2,175
  • 17
  • 19
  • I change to iOS 6.1 now, but it didn't work. And the RK version is 0.20.0pre4. The stacktrace show that the crash point is `rumor.updateDate = [NSDate date]`. – Ray Shih Mar 04 '13 at 17:45
  • Are you sure that [self managedContext] is set (and is not a typo)? log out your "rumor" variable and make sure you did in fact get a Rumor object back from your new context. – G. Shearer Mar 04 '13 at 19:00
  • I'm pretty sure. Here is the log: ` 2013-03-05 10:16:23.321 rumorssay[39050:c07] parentContext = 2013-03-05 10:16:23.321 rumorssay[39050:4903] rumor = (entity: Rumor; id: 0xaed7d10 ; data: )` – Ray Shih Mar 05 '13 at 02:17