views:

34

answers:

1

I have an Application Delegate class with a enumeration which looks like this:

typedef enum {
    Online = 3500,
    DoNotDisturb = 9500,
    Offline = 18500,
    Away = 15500,
    Busy = 6500,
    BeRightBack = 12500
} status;

Additionally I have a property to set a value from the enumerator in my interface file:

@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
    status userStatus;
}

@property (nonatomic, setter=setStatus) status userStatus;

@end

Finally I have the following message in my implementation file:

@implementation Communicator2AppDelegate

- (void)setStatus:(status)_userStatus {
    if ([NSThread isMainThread]) {
        // some stuff happens here ...
    } else {
        [self performSelectorOnMainThread:@selector(setStatus:) withObject:_userStatus waitUntilDone:NO];
    }
}

My issue is the following: the performSelectorOnMainThread message isn't working because it doesn't accept '_userStatus' as a value. My guess is the message assumes it's an enum, not a real value. I get the following error message upon compilation: "Incompatible type for argument 2 of 'performSelectorOnMainThread:withObject:waitUntilDone.'"

Does anyone have any idea on how to make this work?

+1  A: 

You need to pass an object value to this method and enum (that is int) is scalar value. To achieve what you need you must wrap your integer to obj-c object (e.g. NSNumber):

- (void)setStatus:(status)_userStatus {
    if ([NSThread isMainThread]) {
        // some stuff happens here ...
    } else {
        [self performSelectorOnMainThread:@selector(setStatus:) withObject:[NSNumber numberWithInt:_userStatus] waitUntilDone:NO];
    }
}
Vladimir
Thanks mate, it's actually so logical that I wonder why I didn't come up with it myself - especially since the message actually has a parameter 'withObject:' :)
Wolfgang Schreurs