&self的类型转换会导致编译器错误

Fei*_*anZ 9 objective-c ios xcode4 automatic-ref-counting

在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];
Run Code Online (Sandbox Code Playgroud)

将参数设置为索引2(&self)会导致以下编译器错误:

将*const __strong*发送到void*类型的参数会更改retain/release属性

我不知道如何在保持有效代码的同时解决这个问题.目前我只是坚持NULL并在try/catch块中包装invoke语句,但这是一个不太理想的解决方案.


类似的问题,如果有人也愿意解决它:

使用这行代码(来自MPOAuth库)

status = SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary, (CFTypeRef *)&attributesDictionary);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

使用ARC不允许使用指向'CFTypeRef '(又名'const void* ')的Objective-C指针的间接指针

Chr*_*lay 13

您应该能够将其强制转换为适当的指针类型:

NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:delegate];
[invocation setSelector:@selector(restClient:loadedFile:contentType:eTag:)];
Foo *foo = self;
[invocation setArgument:&foo atIndex:2];
[invocation setArgument:&filename atIndex:3];
[invocation setArgument:&contentType atIndex:4];
[invocation setArgument:&eTag atIndex:5];
Run Code Online (Sandbox Code Playgroud)


Fei*_*anZ 0

我发现我可以有选择地对文件使用 ARC,而不是更改 SDK(Dropbox 表示他们将很快发布兼容 ARC 的版本)。所以我就这么做了。

然后我升级到1.0b2,它被打包成一个库,所以问题就解决了。