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

918 阅读1分钟

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

1.Xcode自定义代码块

方式一:
1.选中代码块 
2.鼠标右键,选择`Create Code Snippet...`

659755-1b5dee455adfd843.webp

方式二:
1.选中Xcode导航上的`Editor`
2.选择`Create Code Snippet...`

659755-47b2c388256dd976.webp

2.编辑代码块

659755-f8cb53a08197652d.webp

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/