I'd like to call (void)setDoubleValue:(double)value
using performSelectorOnMainThread:
.
What I thought would work is:
NSNumber *progress = [NSNumber numberWithDouble:50.0];
[progressIndicator performSelectorOnMainThread:@selector(setDoubleValue:)
withObject:progress
waitUntilDone:NO];
Didn't work.
Then I implemented a helper method:
- (void)updateProgressIndicator:(NSNumber *)progress
{
[progressIndicator setDoubleValue:[progress doubleValue]];
}
Works, but not really clean.
After that I tried it with NSInvocation
.
NSInvocation *setDoubleInvocation;;
SEL selector = @selector(setDoubleValue:);
NSMethodSignature *signature = [[progressIndicator class]
instanceMethodSignatureForSelector:selector];
setDoubleInvocation = [NSInvocation invocationWithMethodSignature:signature];
[setDoubleInvocation setSelector:selector];
[setDoubleInvocation setTarget:progressIndicator];
double progress = 50.0;
[setDoubleInvocation setArgument:&progress atIndex:2];
[setDoubleInvocation performSelectorOnMainThread:@selector(invoke)
withObject:nil
waitUntilDone:NO];
This solution works, but it uses a lot of code and is quite slow. (Even if I store the invocation.)
Is there any other way?