iOS提升开发效率-常用代码块

Xcode支持自定义代码段,当输入某个关键字就能提示出某个代码段。 
把常用的代码段保存下来,绝对对开发效率有很大的提高。 

一、添加代码块:

在Xcode中右键,如下图

iOS提升开发效率-常用代码块_第1张图片

选择‘Create Code Snippet’,即可创建新的代码块,

iOS提升开发效率-常用代码块_第2张图片

比如我新建了一个定义block的代码块,

iOS提升开发效率-常用代码块_第3张图片

保存之后,在需要的地方,输入qblo的时候就会有代码块提示,如下图

iOS提升开发效率-常用代码块_第4张图片

选中回车后,我们需要的代码块就有了

iOS提升开发效率-常用代码块_第5张图片

二、常用代码块

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的该目录下即可使用。

 

 

你可能感兴趣的:(iOS)