I have the following method:
- (NSMutableArray *)getElements:(NSString *)theURL;
And I wanted to know if there is a way to call that method using performSelectorOnMainThread so that I can get the return value. So far, I've tried with:
myArray = [object performSelectorOnMainThread:@selector(getElements:)
withObject:url waitUntilDone:YES];
but it doesn't work, since performSelectorOnMainThread returns void. How could I solve this?
Welcome to a multi-threaded environment my friend.
You'll need to store the return value in an instance variable or pass in an object by reference through the withObject
parameter:
NSMutableDictionary *myDict;
[object performSelectorOnMainThread:@selector(getElements:)
withObject:&myDict waitUntilDone:YES];
Your method prototype should now look like this:
- (void)getElements:(NSMutableDictionary **)objects;
You can't do it directly, because, as you say, that method returns void.
So, you'd have to arrange another way to get a value back, for example by passing an NSDictionary instead of an NSString, and having the method store the result in the dictionary for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With