14

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

+ (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 参数以进行回写

在出现以下命令的行上:

[self SHL_initPersonPropertyNamesWithArray:&propertyNames] : NULL;
4

1 回答 1

27

这种情况需要 __strong 存储限定符。

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

但是,此代码不遵循Basic Memory Management Rules

您拥有您创建的任何对象

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

你为什么要这样做?

于 2011-09-14T20:37:57.377 回答