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的。

  • 相关阅读:
    Redis数据库属于nosql数据库类型的一种,什么是nosql数据库,和传统关系型数据库比较,以及windows版本的Redis安装
    redis测试100万并发请求 redis-benchmark -h localhost -p 6379 -c 100 -n 10000
    yum install gcc-c++
    反射技术实战
    违反完整约束条件***已找到子记录的删除方法
    C# 连接和操作SQL SERVER数据库
    C#设计模式学习笔记
    C# 获取windows特殊路径
    Android中的颜色设置
    十个值得一试的开源深度学习框架
  • 原文地址:https://www.cnblogs.com/pengsi/p/8513894.html
Copyright © 2011-2022 走看看