Automatic Reference Counting Issue: Passing address of non-local object to __autoreleasing parameter for write-back(自动引用计数问题:将非本地对象的地址传递给 __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 参数以进行回写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:自动引用计数问题:将非本地对象的地址传递给
基础教程推荐
- Android:STATE_SELECTED不工作 2022-01-01
- - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view 如何工作 2022-01-01
- 新的@SystemApi 注解是什么意思,和@hide 有什么区别 2022-01-01
- 可可/目标C(OSX不是iOS)从子对象访问父对象 2022-01-01
- 突出显示朗读文本(在 iPhone 的故事书类型应用程序中) 2022-01-01
- 在 Android 模拟器中激活网络位置提供程序? 2022-01-01
- 在 appComponent dagger 2 中动态添加测试模块? 2022-01-01
- 如何将多个组件添加到 PickerView? 2022-01-01
- 我的 UIImageView 的任务 2022-01-01
- 在 iOS8 中无法获得正确的键盘高度值 2022-01-01
