(NSNumber **)value和(NSNumber * __autoreleasing *)value

今天在看别人开源项目的时候看到这样的代码:

正文从这里开始~~~

定义如下:

/**
 评论详情页基础设置
 @param BaseSettingBlock 基础设置
 */
- (void)setUpComPicAttribute:(void(^)(NSArray **imageArray,NSString **comComtent,NSString **comSpecifications,NSInteger *selectCount))BaseSettingBlock;

实现如下:

#pragma mark - 基础设置
- (void)setUpComPicAttribute:(void(^)(NSArray **imageArray,NSString **comComtent,NSString **comSpecifications,NSInteger *selectCount))BaseSettingBlock{
    
    NSArray *imageArray;
    NSString *comSpecifications;
    NSString *comComtent;
    
    NSInteger selectCount;

    if (BaseSettingBlock) {
        BaseSettingBlock(&imageArray,&comComtent,&comSpecifications,&selectCount);
        
        self.imageArray = imageArray;
        self.comComtent = comComtent;
        self.comSpecifications = comSpecifications;
        self.selectCount = selectCount;
    }   
}

调用如下:

注意: 这里调用的时候__autoreleasing是系统默认加上的

[dcComVc setUpComPicAttribute:^(NSArray *__autoreleasing *imageArray, NSString *__autoreleasing *comComtent, NSString *__autoreleasing *comSpecifications, NSInteger *selectCount) {
        
        *imageArray = weakSelf.picUrlArray;
        *comComtent = weakSelf.comContent;
        *comSpecifications = weakSelf.comSpecifications;
        
        *selectCount = indexPath.row;
    }];

爱学习的思思赶紧百度下这种写法,原来这里涉及到iOS开发ARC内存管理技术了。

以下两句代码意义是相同的:

NSString *str = [[[NSString alloc] initWithFormat:@"hehe"] autorelease]; // MRC
NSString *__autoreleasing str = [[NSString alloc] initWithFormat:@"hehe"]; // ARC

__autoreleasing在ARC中主要用在参数传递返回值(out-parameters)和引用传递参数(pass-by-reference)的情况下。

以下代码是等同的:

- (NSString *)doSomething:(NSNumber **)value
{
        // do something  
}
- (NSString *)doSomething:(NSNumber * __autoreleasing *)value
{
        // do something  
}

除非你显式得给value声明了__strong,否则value默认就是__autoreleasing的。

原文地址:https://www.cnblogs.com/pengsi/p/8513894.html