我正在尝试实现一种在后台执行任务然后在主线程上调用块的方法:
+ (void)migrateStoreWithCompletionHandler:(MigrationControllerCompletion)completion
{
MigrationController *controller = [[MigrationController alloc] initWithCompletionBlock:completion];
[controller migrateStore];
}
这是-initWithCompletionBlock:
方法:
- (id)initWithCompletionBlock:(MigrationControllerCompletion)completion
{
self = [super init];
if (self)
{
_completion = [completion copy];
}
return self;
}
后台工作发生在-migrateStore
. 问题是 ARCcontroller
在[controller migrateStore]
. 因为controller
是持有块的对象,所以我无法调用它。有人对如何解决此问题有任何建议吗?