I was reading the documentation on Grand Central Dispatch, and there are two functions called Block_copy and Block_release.
According to the documentation these methods are being used while calling dispatch_async to take care of the memory management of the block. Am I suppose to do the same thing in my code?
Is there a problem with my code below?
typedef void (^MyCompletionHandler)(NSError *error)
@interface ServiceClient
- (void)fetchWithCompletionHandler:(MyCompletionHandler)completionHandler;
@property (nonatomic, assign) MyCompletionHandler completionHandler;
@end
@implementation ServiceClient
@synthesize completionHandler = _completionHandler;
- (void)fetchWithCompletionHandler:(MyCompletionHandler)completionHandler
{
self.completionHandler = completionHandler;
[self performSelectorInBackground:@selector(fetchInBackground)];
}
@end
You should use the following declaration:
With
assignyour block will not be retained, butcopywill performBlock_copyautomatically.