iOS提升開發效率-常用代碼塊

Xcode支持自定義代碼段,當輸入某個關鍵字就能提示出某個代碼段。 
把常用的代碼段保存下來,絕對對開發效率有很大的提高。 

一、添加代碼塊:

在Xcode中右鍵,如下圖

選擇‘Create Code Snippet’,即可創建新的代碼塊,

比如我新建了一個定義block的代碼塊,

保存之後,在需要的地方,輸入qblo的時候就會有代碼塊提示,如下圖

選中回車後,我們需要的代碼塊就有了

二、常用代碼塊

1.strong

/** <#描述#> */

@property (nonatomic,strong) <#class#> *<#classname#>;

2.weak

/** <#描述#> */

@property (nonatomic,weak) <#class#> *<#classname#>;

3.代理

/**<#代理描述#>*/

@property (nonatomic, weak)       id<<#protocol#>> <#delegate#>;

4.copy

/** <#描述#> */

@property (nonatomic,copy) <#class#> *<#classname#>;

5.block

/**<#描述#>*/

@property (nonatomic, copy)       void(^<#Block#>)(<#block#>);

6.assign

/** <#描述#> */

@property (nonatomic,assign) <#class#> <#classname#>;

7.block定義

/**<#描述#>*/

typedef <#returnType#>(^<#name#>)(<#arguments#>);

8.tableviewCell

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return <#expression#>;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *ID = @"<#string#>";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];

    }

    <#config the cell#>

    return cell;

}

9.init

- (instancetype)init

{

    self = [super init];

    if (self) {

        <#statements#>

    }

    return self;

}

10.instance

static <#Class#> *instance = nil;

+ (instancetype)shareManager {

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

        instance = [[self alloc] init];

    });

    return instance;

}

+ (instancetype)allocWithZone:(struct _NSZone *)zone {

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

        instance = [super allocWithZone:zone];

    });

    return instance;

}

- (instancetype)init {

    if (self = [super init]) {

        <#Initialization property#>

    }

    return self;

}

等等。。。

我們創建的代碼塊會放在 ~/Library/Developer/Xcode/UserData/CodeSnippets 目錄下,我們可以拷貝出來放到新電腦的xcode的該目錄下即可使用。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章