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

Automatic Reference Counting Issue: Passing address of non-local object to __autoreleasing parameter for write-back(自动引用计数问题:将非本地对象的地址传递给 __autoreleasing 参数以进行回写)
本文介绍了自动引用计数问题:将非本地对象的地址传递给 __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

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

However, this code doesn't follow the Basic Memory Management Rules.

您拥有您创建的任何对象

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).

你为什么要这样做?

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
Game center facebook like(游戏中心 facebook 喜欢)
Objective-C++ importing C++ class fails, cassert not found(Objective-C++ 导入 C++ 类失败,未找到 cassert)