Skip to content

Instantly share code, notes, and snippets.

@chance395
Last active March 9, 2019 08:51
Show Gist options
  • Save chance395/67170d9fd172e06e3dda9cfaea0461b5 to your computer and use it in GitHub Desktop.
Save chance395/67170d9fd172e06e3dda9cfaea0461b5 to your computer and use it in GitHub Desktop.
#ios_block
1.表达方式
申明: (返回值类型)(^block名)(参数列表);
变量形式: ^(形参列表){
codes...
}
tydef: typedef (返回值类型)(^block名)(参数列表);
函数中:
1.第一种边定义边使用,当成一段函数直接调用
void(^UpdateUIBlock)(void) = [^{
UITableView * tableView = self.contactsListView.tableView;
[UIView setAnimationsEnabled:NO];
[tableView reloadData];
[UIView setAnimationsEnabled:YES];
} copy];
[NSThread isMainThread] ? updateUIBlock() :dispatch_async(dispatch_get_main_queue(), updateUIBlock);
2.返回一个回调参数,这种必须对Block赋值,一种是下面,还有一种是setter
@property (nonatomic, strong) void (^dispath_queueNoParaCompletion)(void);
+(void)callMainQueueWithCompletionBlock:(void(^)(void))completionBlock
{
if (completionBlock) {
self.dispath_queueNoParaCompletion = completionBlock;
}
dispatch_async(dispatch_get_main_queue(), ^{
!self.dispath_queueNoParaCompletion ? :self.dispath_queueNoParaCompletion();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment