Xcode 快速開發 代碼塊

Xcode的代碼片斷(Code Snippets)建立自定義的代碼片斷,當你重用這些代碼片斷時,會給你帶來很大的方便。

經常使用的:

1.strong:
@property (nonatomic,strong) <#Class#> *<#object#>;
2.weak:
@property (nonatomic,weak) <#Class#> *<#object#>;
3.copy:
@property (nonatomic,copy) NSString *<#string#>;
4.assign:
@property (nonatomic,assign) <#Class#> <#property#>;
5.delegate:
@property (nonatomic,weak) id<<#protocol#>> <#delegate#>;
6.block:
@property (nonatomic,copy) <#Block#> <#block#>;
7.mark:
#pragma mark <#mark#>
8.ReUseCell:async

static NSString *rid=<#rid#>;  

 <#Class#> *cell=[tableView dequeueReusableCellWithIdentifier:rid];  

 if(cell==nil){  

 cell=[[<#Class#> alloc] initWithStyle:UITableViewCellStyleDefault      reuseIdentifier:rid];  

 }  

 return cell;

9.MainGCD:atom

dispatch_async(dispatch_get_main_queue(), ^{  
<#code#>  
  });

10.AfterGCD:spa

 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<#delayInSeconds#> * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{  
<#code to be executed after a specified delay#>  
});

11.OnceGCD:code

 static dispatch_once_t onceToken;  
 dispatch_once(&onceToken, ^{  
<#code to be executed once#>  
 });

自定義代碼片斷:

以Strong爲例:
1.在書寫@property屬性的地方寫下以下語句:
@property (nonatomic,strong) <#Class#> *<#object#>;orm

2.選中上述語句,用鼠標左鍵拖到 下圖中指示的代碼片斷在Xcode中的區域裏,就新建了一個代碼片斷blog

1518951-56d8edf5f660204b.png

屏幕快照 2016-09-28 上午11.01.52.png

3.鬆開鼠標左鍵的同時,會彈出代碼片斷編輯窗口,以下圖所示:ip

1518951-394fdb2756a05d90.png

屏幕快照 2016-09-28 上午10.56.47.png


圖中從上到下的含義依次是:
①Title
代碼片斷的標題
②Summary
代碼片斷的描述文字
③Platform
能夠使用代碼片斷的平臺,有IOS/OS X/All三個選項
④Language
能夠在哪些語言中使用該代碼片斷
⑤Completion Shortcut
代碼片斷的快捷方式,例:copy
⑥Completion Scopes
能夠在哪些文件中使用當前代碼片斷,好比所有位置,頭文件中等,固然能夠添加多個支持的位置。
最後的一個大得空白區域是對代碼片斷的效果預覽。
一切設置完成之後,點擊該菜單右下角的Done按鈕,新建工做就結束了。ci

代碼片斷備份:

Xcode中的代碼片斷默認放在下面的目錄中:get

~/Library/Developer/Xcode/UserData/CodeSnippetsstring

咱們能夠將目錄中的代碼片斷備份,也能夠將其直接拷出來放在不一樣的電腦上使用。

相關文章
相關標籤/搜索