zoukankan      html  css  js  c++  java
  • (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的。

  • 相关阅读:
    clientcontainerThrift Types
    测试项目测试计划
    执行delete触发器及示例演示
    互联网平台再谈互联网平台化糗百成功案例
    问题错误功能测试报告
    方法结构Oracle查看表结构的几种方法
    内容选择android控件之Spinner(动态生成下拉内容)
    混合服务VMware混合云–IaaS三国演义?
    数据schemaAvro简介
    按钮数据测试用例
  • 原文地址:https://www.cnblogs.com/pengsi/p/8513894.html
Copyright © 2011-2022 走看看