Xcode Snippets

xcode4 引入了一個(gè)新 feature: code snippets,幫助提高效率

圖解

示例圖片

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

1:防止block循環(huán)引用

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 第一篇第二篇大概是把下載圖片緩存圖片的這個(gè)邏輯走完了,里面涉及好多類。 羅列一下 UIView+WebCache ...
    充滿活力的早晨閱讀 854評(píng)論 0 1
  • Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,693評(píng)論 19 139
  • 一、前言 本篇博文介紹的是iOS中常用的幾個(gè)多線程技術(shù): NSThread GCD NSOperation 由于a...
    和玨貓閱讀 659評(píng)論 0 1
  • 一、前言 上一篇文章iOS多線程淺匯-原理篇中整理了一些有關(guān)多線程的基本概念。本篇博文介紹的是iOS中常用的幾個(gè)多...
    nuclear閱讀 2,152評(píng)論 6 18
  • 設(shè)計(jì)模式是什么? 你知道哪些設(shè)計(jì)模式,并簡(jiǎn)要敘述?設(shè)計(jì)模式是一種編碼經(jīng)驗(yàn),就是用比較成熟的邏輯去處理某一種類型的事...
    irenb閱讀 5,387評(píng)論 1 21

友情鏈接更多精彩內(nèi)容