在 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
) 会导致以下编译器错误:
Sending *const __strong * to parameter of type void * changes retain/release properties
我不知道如何在保持有效代码的同时解决这个问题。目前我只是坚持使用 NULL
并将 invoke 语句包装在 try/catch block 中,但这是一个不太理想的解决方案。
一个类似的问题,如果有人愿意解决它:
使用这行代码(来自 MPOAuth 库)
status = SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary, (CFTypeRef *)&attributesDictionary);
出现以下错误
Cast of an indirect pointer to an Objective-C pointer to 'CFTypeRef ' (aka 'const void *') is disallowed with ARC
最佳答案
你应该能够转换它以获得合适的指针类型:
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];
关于objective-c - &self 的类型转换导致编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7549209/