iOS Xcode自定义代码块及常用代码块

传送门HLCodeBlocks,直接拷贝至~/Library/Developer/Xcode/UserData/即可

1.Xcode自定义代码块

方式一:
1.选中代码块 
2.鼠标右键,选择`Create Code Snippet...`
图片.png
方式二:
1.选中Xcode导航上的`Editor`
2.选择`Create Code Snippet...`
图片.png

2.编辑代码块

图片.png

3.常用代码块

weakSelf

__weak typeof(self) weakSelf = self;

strongSelf

__strong typeof(weakSelf) strongSelf = weakSelf;

pstring

@property (nonatomic, copy) NSString *

pstringn

@property (nonatomic, copy) NSString *<#name#>

pstrong

@property (nonatomic, strong)

pcopy

@property (nonatomic, copy)

passign

@property (nonatomic, assign)

pprotocol

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

tdd UITableView的dataSource、delegate

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return <#expression#>;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    <#Class#> *cell = [tableView dequeueReusableCellWithIdentifier:<#(nonnull NSString *)#> forIndexPath:indexPath];
    
    return cell;
}

#pragma mark - UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return <#expression#>;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

cdd UICollectionView的dataSource、delegate、delegateFlowLayout

#pragma mark - UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return <#expression#>;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    <#Class#> *cell = [collectionView dequeueReusableCellWithReuseIdentifier:<#(nonnull NSString *)#> forIndexPath:indexPath];
    return <#expression#>;
}

#pragma mark - UICollectionViewDelegate

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}

#pragma mark - UICollectionViewDelegateFlowLayout

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return <#expression#>;
}

afterGCD延时

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        <#code#>
    });

shared单例

+ (instancetype)sharedInstance {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[<#Class#> alloc] init];
    });
    return instance;
}

mark mark标注

#pragma mark - Private Mehtod

#pragma mark - Public Mehtod

#pragma mark - Response Event

mainGCD回到主线程

dispatch_async(dispatch_get_main_queue(), ^{
        <#code#>
    });

4.以上代码块拷贝至一下路径:

传送门HLCodeBlocks

~/Library/Developer/Xcode/UserData/
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容