【发布时间】:2011-09-25 23:03:21
【问题描述】:
在 ARC 环境中,我有以下代码:
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:delegate];
[invocation setSelector:@selector(restClient:loadedFile:contentType:eTag:)];
// Error Here!
[invocation setArgument:&self atIndex:2];
[invocation setArgument:&filename atIndex:3];
[invocation setArgument:&contentType atIndex:4];
[invocation setArgument:&eTag atIndex:5];
将参数设置为索引 2 (&self) 会导致以下编译器错误:
将 *const __strong * 发送到 void * 类型的参数会更改保留/释放属性
我不知道如何在保留有效代码的同时解决此问题。目前我只是坚持NULL 并将调用语句包装在 try/catch 块中,但这是一个不太理想的解决方案。
一个类似的问题,如果有人也愿意解决它:
使用这行代码(来自 MPOAuth 库)
status = SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary, (CFTypeRef *)&attributesDictionary);
我收到以下错误
ARC不允许使用指向'CFTypeRef '(又名'const void *')的Objective-C指针的间接指针强制转换
【问题讨论】:
-
有什么特别的原因为什么要在这里使用 NSInvocation 而不是块?
-
我不确定,它是 Dropbox SDK 的一部分。我只是让它符合 ARC,尽量不要把代码弄乱太多。
标签: objective-c ios xcode4 automatic-ref-counting