Xcode 創建自定義的代碼片段,將經常重復使用的代碼保存起來,方便快速開發。
在Xcode 右下角選擇{CodeSnippet}
Xcode 創建自定義的代碼片段,將經常重復使用的代碼保存起來,方便快速開發。
代碼片段存放在
~/Library/Developer/Xcode/UserData/CodeSnippets
可以將文件拷貝出來,放在不同的電腦上使用
-
在Xcode 右下角選擇 {CodeSnippet}
- 自定義代碼片段
- 選中代碼片段,鼠標變成箭頭后(Xcode9 需要長按2秒鐘)拖拽到 {CodeSnippet}中,雙擊彈出編輯窗口
-
編輯
- Title
代碼塊標題 - Summary
描述文字 - Platform
使用的平臺All/iOS/macOS/tvOS/watchOS - Language
使用的語言場景 - Completion Shortcut
使用的快捷方式 - Completion Scopes
代碼塊的使用位置
@property (nonatomic, strong) <#Class#> *<#object#>;
@property (nonatomic, weak) <#Class#> *<#object#>;
@property (nonatomic, copy) NSString *<#string#>;
@property (nonatomic, assign) <#Class#> <#property#>;
@property (nonatomic, weak) id<<#protocol#>> <#delegate#>;
@property (nonatomic, copy) <#Block#> <#block#>;
#pragma mark -- <#mark#>
static NSString *identifier = <#rid#>;
<#Class#> *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
if(!cell){
cell=[[<#Class#> alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
return cell;
MainGCD
dispatch_async(dispatch_get_main_queue(), ^{
<#code#>
});
AfterGCD
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#>
});
OnceGCD
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
<#code to be executed once#>
});