While iOS 14 and macOS Big Sur 11 are in public beta, I'd like to add some conditional code to work around significant issues. I'm still building my app with the current SDKs because I plan to release updates before the fall, when the new OS versions are released.
Some time back, the recommended way to handle this in Objective-C was to check if a class existed before using it:
Or you could check if a class had been added to an existing method:
Then at some point we got #available in Swift and @available in Objective-C, which is now the recommended way to handle this:
This works great if you are building your app with the iOS 14 SDK, but from what I can tell the condition is simply ignored if you are building with an older SDK, at least in Swift.
I could go back the old NSClassFromString or respondsToSelector: approach, but I would prefer to handle this in Swift if it's possible. I also have some cases where there's not really a new class or method to check for—it's just new behavior I want to accommodate. What's the best way to handle these cases?
Some time back, the recommended way to handle this in Objective-C was to check if a class existed before using it:
Code Block if (NSClassFromString(@"UINewClassName"))
Or you could check if a class had been added to an existing method:
Code Block if ([object respondsToSelector:@selector(newMethodName:)]) {
Then at some point we got #available in Swift and @available in Objective-C, which is now the recommended way to handle this:
Code Block if #available(iOS 14, *)
Code Block if (@available(iOS 14.0, *))
This works great if you are building your app with the iOS 14 SDK, but from what I can tell the condition is simply ignored if you are building with an older SDK, at least in Swift.
I could go back the old NSClassFromString or respondsToSelector: approach, but I would prefer to handle this in Swift if it's possible. I also have some cases where there's not really a new class or method to check for—it's just new behavior I want to accommodate. What's the best way to handle these cases?