🔥 iOS Development ☛【Xcode快捷代码】

Github Demo: https://github.com/BaHui/BHShortcutCode

简介

开发中Xcode常用的快捷代码块, 提高开发效率.

添加:

  1. 关闭Xcode;
  2. 将Demo中的 CodeSnippets 文件夹下的文件拷贝到 ~/Library/Developer/Xcode/UserData/CodeSnippets, 若本地没有CodeSnippets文件夹, 则新建一个文件夹, 名字为CodeSnippets 然后把文件拷贝在这个文件夹下.
  3. 重新启动Xcode, 可以看到工具栏多出来新增的代码块.

自定义内容:

// 静态字符: static_string
static NSString *const <#StringName#> = <#StringValue#>;

// 静态数值: static_basic
static const <#BasicType#> <#BasicName#> = <#BasicValue#>;
// Strong 类型属性: property_strong
@property (nonatomic, strong) <#Class#> *<#object#>;

// Assign 类型属性: property_assign
@property (nonatomic, assign) <#Class#> <#property#>;

// Copy 类型属性: property_copy
@property (nonatomic, copy) <#Class#> *<#name#>;

// Weak 类型属性: property_weak
@property (nonatomic, weak) <#Class#> *<#object#>;

// Delegate 类型属性: property_delegate
@property (nonatomic, weak) id <<#protocol#>> delegate;
// Mark生命周期: mark_VCLifeCycle
#pragma mark - ViewController LifeCycle

// Mark按钮点击: mark_IBAction
#pragma mark - IBAction Methods

// Mark公开方法: mark_Public Methods
#pragma mark - Public Methods

// Mark私有方法: mark_Private Methods
#pragma mark - Private Methods

// Mark自定义: mark_Normal
#pragma mark - <#description#>

// Mark滚动视图代理: mark_UIScrollViewDelegate
#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

}

// Mark表代理: mark_UITableViewDelegate
#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];
}
// GCD回到主线程: gcd_main_queue
  dispatch_async(dispatch_get_main_queue(), ^{
  <#code#>
  });

// GCD延时: gcd_after
 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#>
  });

// GCD单例: gcd_onceToken
+ (instancetype)sharedInstance {
  static <#Class#> *<#object#> = nil;

  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
  <#object#> = [[<#Class#> alloc] init];
  });

  return <#object#>;
}
// 枚举: type_enum
typedef NS_ENUM(NSInteger, Type) {
  Type = 0, // <#description#>
  Type = 1, // <#description#>
  Type = 2, // <#description#>
};

// 有返回值的Block: block_return
typedef void (^<#BlockName#>) (<#Class#> *<#object#>);

// 无返回的Block: block_void
typedef void (^<#BlockName#>) (void);

// 表内容偏移: tableView_inset
self.tableView.contentInset = UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>);

提示: 快捷方式的命名可以自定义, 将Demo中的文件快捷方式名称改为符合自己编码习惯的名称.

使用举例:

以定义一个有返回值得Block为例子:

  • 在Xcode中输入 block
  • 回车快捷方式便可得到:typedef void (^<#BlockName#>) (<#Class#> *<#object#>);

交流与建议

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,027评论 3 119
  • 在深圳出差,选了一家新开的公寓。刚入住的时候很满意,房间大,装修好,价格还不贵,还以为赚到了。 晚上要睡觉的时候,...
    Angelina1124阅读 141评论 0 0
  • 什么都没有了 城市,人,回忆 都在薄暮般的清晨出发 消失在光线停顿的时间终点 什么都重现了 盛夏,连衣裙,和你 像...
    乌鸦之白阅读 158评论 0 2