Xcode可重用程式碼塊code snippets
阿新 • • 發佈:2018-11-01
一. 關於code snippets
通過Xcode的重用程式碼塊(code snippets)可快速輸入預設好的常用程式碼模板,如通過鍵入
hystrong
系統會直接替代為
@property(nonatomic,strong) <#class#> <#name#>;
二. 新增方法
如下圖進行選擇,我們看到Xcode已經自帶一些code snippets,直接拖拽到程式碼輸入區域就可使用。
現在我們來新增一些我們常用的,例如宣告assign,strong,copy屬性等,我們在程式碼編輯區域輸入
@property (nonatomic,strong) <#class#> <#name#>;
然後選中整行程式碼(觸控板連續點選3下),拖拽到上圖紅框中的code snippets區域(觸控板三指移動),編輯名稱、描述以及快捷的shortcut,然後點選done儲存。
那麼以後需要鍵入strong屬性時,我們只要輸入hystrong即會聯想出我們需要的完整程式碼:
三. 我常用的一些code snippets
hystrong , strong屬性:
@property(nonatomic,strong) <#class#> <#name#>;
hyassign, assign屬性:
@property(nonatomic,assign) <#class#> <#name#>;
hycopy, copy屬性:
@property(nonatomic,copy) <#class#> <#name#>;
hyaddObserver , 新增監聽:
[[NSNotificationCenter defaultCenter] addObserver:<#(nonnull id)#> selector:<#(nonnull SEL)#> name:<#(nullable NSNotificationName)#> object:<#(nullable id)#>];
hyremoveObserver , 移除監聽:
[[NSNotificationCenter defaultCenter] removeObserver:self];
hytableview , hytableview的資料來源和代理方法(只實現常用幾個):
#pragma mark - TableViewDelegate & Datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return <#expression#>;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
return <#expression#>;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
hypm, pragma mark標記:
#pragma mark - <#title#>