Xcode Snippets

2016-04-13  本文已影响0人  天涯人1949

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
唐巧博客

上一篇下一篇

猜你喜欢

热点阅读