How can I change the following code to be compatible with ARC:
MyObj* fn = nil;
[self performSelectorOnMainThread:@selector(popSomething:) withObject:(id)&fn waitUntilDone:YES];
Right now, I get the following error:
error: cast of an indirect pointer to an Objective-C pointer to '__strong id' is disallowed with ARC [4]
If you're expecting the main thread to update the string, then a better way to do it would be to use a mutable string and simply pass it to the main thread:
Then the main thread can simply update the string.
The type of the argument should be
(id *)
, ie. a pointer to an object, not an object.But if you just want to return a value from a method that you need to execute on the main thread, a nicer solution is to use blocks and GCD:
This executes the method
-popFilename
on the main thread, and stores the result inpoppedFilename
. You must be careful not to call this method on the main thread, as it would deadlock. If you aren't sure if you are on the main thread, you could use something like this: