版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dolacmeng/article/details/71631613
一. 关于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#>