9
votes

In an ARC environment, I have the following code:

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];

Setting the argument to index 2 (&self) causes the following compiler error:

Sending *const __strong * to parameter of type void * changes retain/release properties

I have no idea how to fix this while keeping valid code. At the moment I'm just sticking in NULL and wrapping the invoke statement in a try/catch block, but that's a less-than-ideal solution.


A similar issue, if anyone would be kind enough to address it as well:

With this line of code (from the MPOAuth library)

status = SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary, (CFTypeRef *)&attributesDictionary);

I get the following error

Cast of an indirect pointer to an Objective-C pointer to 'CFTypeRef ' (aka 'const void *') is disallowed with ARC

3
Is there some particular reason why you want to use an NSInvocation instead of a block here?NSResponder
I'm not sure, it's part of the Dropbox SDK. I'm just going through making it ARC-compliant, trying not to mess up the code too much.FeifanZ

3 Answers

13
votes

You should be able to cast it to get an appropriate pointer type:

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];
2
votes

this line:

 status = SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary, (CFTypeRef *)&attributesDictionary);

can be resolved as following:

 CFTypeRef outDictionaryRef;
 status = SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary, &outDictionaryRef;
 attributesDictionary = (__bridge_transfer NSDictionary *) outDictionaryRef;

So in essence just give the reference type it expects as the out param. And when the out param is filled out, transfer the ownership to your cocoa type.

0
votes

Rather than changing the SDK (Dropbox has said that they'll be posting an ARC-compatible version soon), I found out that I can use ARC selectively for a file. So I did that.

And then I upgraded to the 1.0b2, which is packaged as a library and so the issue is solved.