开发中Xcode常用的快捷代码块, 提高开发效率, 通过自定义的快捷字符, 可以快速创建代码, 节约开发时间
添加:
1.关闭Xcode; 2.将Demo中的CodeSnippets文件夹下的文件拷贝到~/Library/Developer/Xcode/UserData/CodeSnippets ,
若本地没有CodeSnippets文件夹, 则新建一个文件夹, 名字为CodeSnippets 然后把文件拷贝在这个文件夹下. 3.重新启动Xcode, 可以看到工具栏多出来新增的代码块.
自定义内容:
static NSString *const <static const <#BasicType#> <#BasicName#> = <#BasicValue#> ;
@property (nonatomic , strong ) <#Class#> *<#object#> ; @property (nonatomic , assign ) <#Class#> <#property#> ; @property (nonatomic , copy ) <#Class#> *<#name#> ; @property (nonatomic , weak ) <#Class#> *<#object#> ; @property (nonatomic , weak ) id <<#protocol#>> delegate;
#pragma mark - ViewController LifeCycle #pragma mark - ButtonAction Methods #pragma mark - Public Methods #pragma mark - Private Methods #pragma mark - <#description#>
#pragma mark - UIScrollViewDelegate - (void )scrollViewDidScroll:(UIScrollView *)scrollView { }
#pragma mark - UITableViewDataSource - (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView { return <#Sections#>; } - (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger )section { return <#RowCount#>; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { <#CellClass#> *<#cellObject#> = [tableView dequeueReusableCellWithIdentifier:<#CellIdentifier#> forIndexPath:indexPath]; return <#cellObject#>; } #pragma mark - UITableViewDelegate - (CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger )section { return <#HeaderHight#>; } - (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return <#RowHeight#>; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger )section { return <#HeaderView#>; } - (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES ]; }
dispatch_async (dispatch_get_main_queue(), ^{ <#code#> }); 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#> }); + (instancetype )sharedInstance { static <#Class#> *<#object#> = nil; static dispatch_once_t onceToken;dispatch_once (&onceToken, ^{<#object#> = [[<#Class#> alloc] init]; }); return <#object#>; }
typedef NS_ENUM (NSInteger , Type) {Type = 0 , Type = 1 , Type = 2 , }; typedef void (^<#BlockName#>) (<#Class#> *<#object#> ); typedef void (^<#BlockName#>) (void);
提示: 快捷方式的命名可以自定义, 将Demo中的文件快捷方式名称改为符合自己编码习惯的名称.
使用举例:
以定义一个有返回值得Block为例子: 1.在Xcode中输入 block 2.回车快捷方式便可得到:typedef void (^<#BlockName#>) (<#Class#> *<#object#>);
Github Demo: https://github.com/BaHui/BHShortcutCode
交流与建议
近期评论