Wie verwende ich native C-Typen mit performSelectorOnMainThread?

Ich würde gerne anrufen(void)setDoubleValue:(double)value mitperformSelectorOnMainThread:.

Was ich dachte, würde funktionieren, ist:

NSNumber *progress = [NSNumber numberWithDouble:50.0];
[progressIndicator performSelectorOnMainThread:@selector(setDoubleValue:)
                                    withObject:progress
                                 waitUntilDone:NO];

Hat nicht funktioniert

Dann habe ich eine Hilfsmethode implementiert:

- (void)updateProgressIndicator:(NSNumber *)progress
{
    [progressIndicator setDoubleValue:[progress doubleValue]];
}

Funktioniert, aber nicht wirklich sauber.

Danach habe ich es mit probiertNSInvocation.

NSInvocation *setDoubleInvocation;;
SEL selector = @selector(setDoubleValue:);
NSMethodSignature *signature;
signature = [progressIndicator methodSignatureForSelector: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];

Diese Lösung funktioniert, verwendet aber viel Code und ist ziemlich langsam. (Auch wenn ich den Aufruf speichere.)

Gibt es einen anderen Weg?

Antworten auf die Frage(4)

Ihre Antwort auf die Frage