What I'm trying to do is following:
Product *product = [fetchResult lastObject];
NSString *productID = product.atProductID;
dispatch_async(queue, ^(void){
// Something with productID like
NSLog(@"productID is %@", productID);
});
Is it safe to do it this way or do I need to create another context for my secondary queue and get the product by its internal ID and then deal with its atProductID attribute?
Update: Well, it reveals that is actually unsafe. One simple solution is to make a copy of a productID string:
Product *product = [fetchResult lastObject];
NSString *productID = [product.atProductID copy];
dispatch_async(queue, ^(void){
// Something with productID like
NSLog(@"productID is %@", productID);
});
This will be safe as you don't keep any references to context or its derivatives on the background thread. The reason for this is that context caches the data it fetched from the persistent store and it itself manages that cache. And no matter if you keep a pointer to that cache or not it may change or destroy it unless it is used on the context's thread.