小编use*_*193的帖子

使用ARC将指针传递给NSArray内的对象

我正在转换为ARC,并且在没有破坏代码的情况下找不到任何方法来摆脱这个编译器错误.

我需要将2个对象传递给选择器,因此我将它们都添加到数组中,如下所示,并将该数组发送到选择器:

LWPagerContent* content = nil;
NSArray* args = [NSArray arrayWithObjects:article, [NSValue valueWithPointer:&content], nil];

[self performSelectorOnMainThread:@selector(initArticlePagerContent:) withObject:args waitUntilDone:YES];
Run Code Online (Sandbox Code Playgroud)

此方法访问数组,但需要在数组中引用的地址处修改对象.它应该如图所示初始化LWPagerContent对象,然后该对象将由调用performSelector的原始方法使用.

- (void)initArticlePagerContent:(NSArray*)args {
Article* article = [args objectAtIndex:0];

LWPagerContent** contentPtr = [[args objectAtIndex:1] pointerValue];
*contentPtr = [[NSClassFromString([StyleSheet articleContentClass]) alloc] initWithArticle:article];
Run Code Online (Sandbox Code Playgroud)

}

这工作正常,但当我尝试转换为ARC时,我立即被告知"Implicit conversion of a non-Objective-C type 'void *' to 'LWPagerContent *__strong *' is disallowed with ARC".在以"LWPagerContent **..."(上面显示的第二个到最后一个)开头的行上发生此错误.我尝试过使用__bridge__autoreleasing其他帖子中的推荐,但似乎没有任何效果.任何建议都非常感谢.

pointers bridge reference objective-c automatic-ref-counting

1
推荐指数
1
解决办法
439
查看次数