iOS Xcode自定義代碼塊及常用代碼塊

傳送門(mén)HLCodeBlocks,直接拷貝至~/Library/Developer/Xcode/UserData/即可

1.Xcode自定義代碼塊

方式一:
1.選中代碼塊 
2.鼠標(biāo)右鍵,選擇`Create Code Snippet...`
圖片.png
方式二:
1.選中Xcode導(dǎo)航上的`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延時(shí)

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標(biāo)注

#pragma mark - Private Mehtod

#pragma mark - Public Mehtod

#pragma mark - Response Event

mainGCD回到主線(xiàn)程

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

4.以上代碼塊拷貝至一下路徑:

傳送門(mén)HLCodeBlocks

~/Library/Developer/Xcode/UserData/
最后編輯于
?著作權(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)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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