Xcode Snippets

xcode4 引入了一个新 feature: code snippets,帮助提高效率

图解

示例图片

保存目录 ~/Library/Developer/Xcode/UserData/CodeSnippets

1:防止block循环引用

@weakSelf : __weak __typeof(self)weakSelf = self;
@strongSelf: __strong __typeof(weakSelf)strongSelf = weakSelf;

2:定义单例

+ (instancetype)shared<#name#> { static <#class#> *_shared<#name#> = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _shared<#name#> = <#initializer#>; }); return _shared<#name#>; }

3:

title: "dispatch_async Pattern for Background Processing"
summary: "Dispatch to do work in the background, and then to the >main queue with the results"
completion-scope: Function or Method

dispatch_async(dispatch_get_global_queue(<#dispatch_queue_priority_t priority#>, <#unsigned long flags#>), ^(void) { <#code#> dispatch_async(dispatch_get_main_queue(), ^(void) { <#code#> }); });
4:

title: "Documents Directory Path"
completion-scope: Function or Method

NSURL *documentsDirectoryURL = [NSURL fileURLWithPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]];

5:

title: "ImageView"
summary: "Create & Initialize UIImageView with Named Image"
platform: iOS
completion-scope: Code Expression

[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"<#image name#>"]]

6:

title: "Library Directory Path"
completion-scope: Function or Method

[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];

NShipster
唐巧博客

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

推荐阅读更多精彩内容

  • 第一篇第二篇大概是把下载图片缓存图片的这个逻辑走完了,里面涉及好多类。 罗列一下 UIView+WebCache ...
    充满活力的早晨阅读 763评论 0 1
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,837评论 18 139
  • 一、前言 本篇博文介绍的是iOS中常用的几个多线程技术: NSThread GCD NSOperation 由于a...
    和珏猫阅读 585评论 0 1
  • 一、前言 上一篇文章iOS多线程浅汇-原理篇中整理了一些有关多线程的基本概念。本篇博文介绍的是iOS中常用的几个多...
    nuclear阅读 2,068评论 6 18
  • 设计模式是什么? 你知道哪些设计模式,并简要叙述?设计模式是一种编码经验,就是用比较成熟的逻辑去处理某一种类型的事...
    irenb阅读 5,241评论 1 21