我正在尝试将指针传递给指向方法的指针,但显然 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 参数以进行回写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!