自动引用计数问题:将非本地对象的地址传递给__autoreleasing参数以进行回写 [英] Automatic Reference Counting Issue: Passing address of non-local object to __autoreleasing parameter for write-back

查看:89
本文介绍了自动引用计数问题:将非本地对象的地址传递给__autoreleasing参数以进行回写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将指针传递给指向某个方法的指针,但显然ARC在如何操作方面存在一些问题。这里有两种方法:

I'm trying to pass pointer to pointer to a method, but apparently ARC has some issues with how I'm doing it. Here the two methods:

+ (NSString *)personPropertyNameForIndex:(kSHLPersonDetailsTableRowIndex)index 
{
    static NSArray *propertyNames = nil;

    (nil == propertyNames) ? 
        [self SHL_initPersonPropertyNamesWithArray:&propertyNames] : NULL;
}

+ (void)SHL_initPersonPropertyNamesWithArray:(NSArray **)theArray
{
    *theArray = [[NSArray alloc] 
                 initWithObjects:@"name", @"email", @"birthdate", @"phone", nil];
}

我收到以下错误:


自动引用计数问题:将非本地对象的地址传递给__autoreleasing参数以进行回写

Automatic Reference Counting Issue: Passing address of non-local object to __autoreleasing parameter for write-back

在出现以下命令的行上:

On the line which the following command appears:

[self SHL_initPersonPropertyNamesWithArray:&propertyNames] : NULL;


推荐答案

本案需要__strong存储限定符。

The __strong storage qualifier is needed for this case.

+ (void)SHL_initPersonPropertyNamesWithArray:(NSArray * __strong *)theArray

但是,此代码不遵循基本内存管理规则


您拥有自己创建的任何对象

You own any object you create

使用名称以alloc,new,copy或mutableCopy开头的方法创建对象(例如,alloc,newObject或mutableCopy)。

You create an object using a method whose name begins with "alloc", "new", "copy", or "mutableCopy" (for example, alloc, newObject, or mutableCopy).

您想要这样做的原因是什么?

For what reason do you want to do this?

这篇关于自动引用计数问题:将非本地对象的地址传递给__autoreleasing参数以进行回写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆