使用Code Snippet在Xcode中添加代码段

通过code snippets,我们可以创建一些可重用的代码块,并且在任何需要的地方很容易的就可以使用这些代码块。这可以节省输入需要的操作和时间。并且,一旦你 学会使用code snippets,会发现你可以创建并扩充自己的code snippet library。
 
1、创建一个code snippet非常简单。首先,打开Xcode并在utilities panel中选择code snippet library。

2、将写好的代码直接拖入Code Snippet,注意红框内淡淡的字样

3、随即会自动弹出提示框,可以更改对应内容,以便使用(Title为code snippets标题;Completion Shortcut为快捷输入)

任何时候,你都遇到重复输入的相同代码块,都可以考虑将其添加到你的code snippets library中。
 
下面是我经常使用到的一些snippet:
 
1     Title: Animation Block 
2     Completion Shortcut: ab 
3     Completion Scopes: Function or Method 
4       
5     void (^<#Title#>)(void) = ^{ }; 
1     Title: Animation Completion Block 
2     Completion Shortcut: acb 
3     Completion Scopes: Function or Method 
4       
5     void (^<#Title#>)(BOOL) = ^(BOOL finished) { }; 
1     Title: Notification Add 
2     Completion Shortcut: na 
3     Completion Scopes: Function or Method 
4       
5     [[NSNotificationCenter defaultCenter] addObserver:<#Observer#> selector:<#Selector#> name:<#Name#> object:<#Object#>]; 
1     Title: Notification Remove 
2     Completion Shortcut: nr 
3     Completion Scopes: Function or Method 
4       
5     [[NSNotificationCenter defaultCenter] removeObserver:<#Observer#> name:<#Name#> object:<#Object#>]; 
1     Title: NSLog 
2     Completion Shortcut: log 
3     Completion Scopes: Function or Method 
4       
5     NSLog(@"<#Log#>"); 
1     Title: Private Interface 
2     Completion Shortcut: pi 
3     Completion Scopes: Top Level 
4       
5     @interface <#Title#> () 
6       
7     @end 

 1 Title: Property Assign 

2 Completion Shortcut: pa 

3 Completion Scopes: All 

4  @property (assign, nonatomic)  

 1 Title: Property Strong 

2 Completion Shortcut: ps 

3 Completion Scopes: All 

4  @property (strong, nonatomic)  

1     Title: Property Unsafe Unretained 
2     Completion Shortcut: pu 
3     Completion Scopes: All 
4       
5     @property (unsafe_unretained, nonatomic) 

 

 

 

 

 

 

 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值