Xcode可重用代码块code snippets

一. 关于code snippets

通过Xcode的重用代码块(code snippets)可快速输入预设好的常用代码模板,如通过键入

hystrong

系统会直接替代为

@property(nonatomic,strong) <#class#> <#name#>;
二. 添加方法

如下图进行选择,我们看到Xcode已经自带一些code snippets,直接拖拽到代码输入区域就可使用。
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#>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值