Search code examples
iosobjective-cios9performselector

How to use performSelector for object value assignment


I want to use a new LocationManager property in iOS 9, I would write:

if ([_manager respondsToSelector:@selector(allowsBackgroundLocationUpdates)]){
        _manager.allowsBackgroundLocationUpdates = YES;
}

But how to use the performSelector here, so that the line compiles in both XCode 6 and 7, since above would give compile error on XCode 6 as allowsBackgroundLocationUpdates is not available there, one option could have been to use the default object setter method

[_manager performSelector:@selector(setAllowsBackgroundLocationUpdates) withObject:@{1}];

but I see no selector in intellisense for :

setAllowsBackgroundLocationUpdates

so how to write such a statement using performSelector?


Solution

  • Maybe you are missing ":"

    [_manager performSelector:@selector(setAllowsBackgroundLocationUpdates:) withObject:@{1}];