Answer the question
In order to leave comments, you need to log in
How to put Managed Object from block into ManagedObjectContext?
Creating a managed object from a block crashes the application. You need to parse json in mo and put it in context
NSManagedObject *tempObject;
NSManagedObjectContext *temporaryContext = [[NSManagedObjectContext alloc]initWithConcurrencyType:NSPrivateQueueConcurrencyType];
AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
[temporaryContext setParentContext:delegate.mainManagedObjectContext];
for (NSDictionary* objd in objects) {
tempObject = targetParser(objd, temporaryContext);
[objectsArray addObject:tempObject];
}
mutableResult[@"objects"] = [objectsArray copy];
return [mutableResult copy];
return mutableResult;
const static id (^routesDeserializer)(NSDictionary*, NSManagedObjectContext*) = ^id (NSDictionary* d, NSManagedObjectContext* context) {
Route* r = [Route newObjectWithContext:context];
r.identifier = d[resourceIdKey];
r.name = d[resourceNameKey];
r.sequenceDescription = d[routeDescriptionKey];
r.capacityType = d[routeCapacityTypeKey];
r.objectHash = d[resourceHashKey];
r.city = d[resourceCityIdKey];
r.checkpoint = d[routeCheckpointIdsKey];
return r;
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question