iOS開發之FuckingBlockSyntax!
How Do I Declare A Block in Objective-C?
As a local variable:
returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};
As a property:
@property (nonatomic, copy, nullability) returnType (^blockName)(parameterTypes);
As a method parameter:
- (void)someMethodThatTakesABlock:(returnType (^nullability)(parameterTypes))blockName;
As an argument to a method call:
[someObject someMethodThatTakesABlock:^returnType (parameters) {...}];
As a typedef:
typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};
This is not intended to be an exhaustive list of all possible uses of blocks.
If you find yourself needing syntax not listed here, it is likely that a typedef would make your code more readable.
相關文章
- iOS 開發之— NSURLProtocoliOSProtocol
- iOS開發之WebViewiOSWebView
- iOS開發之GCDiOSGC
- iOS之Wifi開發探究iOSWiFi
- iOS開發之逆向工程iOS
- iOS開發之避免crashiOS
- iOS開發之Core AnimationiOS
- iOS開發之 Autolayout 詳解iOS
- iOS開發之protocol和delegateiOSProtocol
- iOS開發之XLForm的使用iOSORM
- iOS開發之網路篇iOS
- IOS開發之sqlite框架FMDBiOSSQLite框架
- iOS開發之UICollectionViewDataSourcePrefetchingiOSUIView
- iOS開發之新浪圍脖iOS
- iOS開發之遠端推送iOS
- iOS開發之微信山寨版iOS
- iOS開發之CocoaLumberjackiOS
- iOS開發之玩轉字串iOS字串
- iOS開發之彈窗管理iOS
- iOS開發之字串轉圖片iOS字串
- iOS開發之Crash分析,以及收集iOS
- ionic開發環境搭建之ios開發環境iOS
- iOS開發之原始碼解析 - MasonryiOS原始碼
- iOS開發之原始碼解析 - MBProgressHUDiOS原始碼
- iOS 開發之照片框架詳解iOS框架
- iOS開發之顯示微博表情iOS
- iOS開發之構建WidgetiOS
- iOS 開發之 ReactiveCocoa(基礎)iOSReact
- iOS開發實用軟體之NWPusheriOS
- iOS開發之OC篇(3)—— NSArray、NSMutableArrayiOS
- iOS 開發之解析Json檔案iOSJSON
- iOS開發之登入與訪客iOS
- iOS 開發之內購 – AppStoreiOSAPP
- iOS之widget開發(Today Extension)iOS
- iOS開發之VPN協議(理論)iOS協議
- iOS開發之掃描二維碼iOS
- iOS開發之整合高德地圖(一)iOS地圖
- iOS開發之NavBar和TarBar使用技巧iOS