【发布时间】:2014-02-18 08:32:10
【问题描述】:
如何使变量的地址成为NSObject 中的强属性?我有一个名为SCPFMessageThreadQuery 的类,它通过传递SCPFMessageThread 变量的地址来进行分配。
@interface SCPFMessageThreadQuery ()
// This declaration seems correct.
@property (nonatomic) SCPFMessageThread *__strong *thread;
- (id)initWithRootMessage:(SCPFMessage *)root threadAddress:(SCPFMessageThread **)address;
@end
@implementation SCPFMessageThreadQuery
// Xcode somehow makes the ownership type __autoreleasing here during autocompletion.
- (id)initWithRootMessage:(SCPFMessage *)root threadAddress:(SCPFMessageThread *__autoreleasing *)address
{
if (self = [super init]) {
_root = root;
// ERROR HERE. Xcode complains about changing the ownership of address.
_thread = address;
}
return self;
}
@end
我得到的错误是:
将 'SCPFMessageThread *__autoreleasing *' 分配给 'SCPFMessageThread *__strong *' 会更改指针的保留/释放属性
我计划在我的视图控制器中以下列方式使用这个类:
SCPFMessageThread *thread = self.thread; // self.thread can be nil
SCPFMessageThreadQuery *query = [[SCPFMessageThreadQuery alloc]
initWithRootMessage:self.rootMessage threadAddress:&thread];
我真的需要在这里传递地址。我将对我们的 API 进行多次调用,以完成应用程序代码中单个对象 (SCPFMessageThread) 的信息。请不要问我为什么 API 不自己做 JOIN。
【问题讨论】:
标签: ios iphone objective-c c pointers