My app needs to be compatible with different OS versions.
How do I detect if a specific class is available to use with the particular OS?
As an example, NSPopover
is only available in Lion and up, so how can I check if the OS supports NSPopover
in case the person is using Snow Leopard?
You could do
if ([TheWantedClass class]) {
// The class exists so run code
} else {
// The class doesn't exist so use an alternate approach
}
or
if (NSClassFromString(@"TheWantedClass") != nil) {
// The class exists
} else {
// The class doesn't exist
}
https://developer.apple.com/documentation/foundation/1395135-nsclassfromstring
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