Xcode Snippets

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

图解

Xcode Snippets_第1张图片
示例图片

保存目录 ~/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
唐巧博客

你可能感兴趣的:(Xcode Snippets)