我有一些变量,它们缓存来自网络服务的一些数据。
为了使我的代码更加动态,我想返回一个指向缓存变量的双指针。 所以它是一个双指针。我在使用 ARC 时遇到一些问题。
这是我得到的:
<小时/>- (id *)pointerToSectionCacheProperty:(SomeSection)section {
switch (section) {
case Section1:
{
return &_section1Cache;
}
break;
case Section2:
{
return &_section2Cache;
}
break;
case Section3:
{
return &_section3Cache;
}
break;
}
return nil;
}
<小时/>
ARC 给我以下错误:
Returning 'NSArray *__strong *' from a function with result type '__autoreleasing id *' changes retain/release properties of pointer
<小时/>
这是错误的做法吗?
如果是这样,正确的方法是什么?
最佳答案
解决方案
<小时/>让它像这样工作:
<小时/>- (NSArray *__strong *)pointerToSectionCacheProperty:(SomeSection)section {
switch (section) {
case Section1:
{
return &_section1Cache;
}
break;
case Section2:
{
return &_section2Cache;
}
break;
case Section3:
{
return &_section3Cache;
}
break;
}
return nil;
}
<小时/>
作为旁注,- (id __strong *)...
也同样有效。
关于iphone - ARC 中双指针的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18856720/