Is it possible to achieve this on the Class level of an object? Specifically looking at this to have an app containing WatchConnectivity but also suppporting iOS8
class Test { if #available(iOS 9, *) { let session: WCSession ...... } } You can use a computed static property:
public class Example { public static var answerToEverything: Int { if #available(iOS 9, *) { return 42 } else { return 0 } } } Or, you can consider using @available attribute instead:
public class Example { @available(iOS, introduced=1.0) public static var answerToEverything: Int = 42 } where 1.0 is the version of your library (not iOS).
This would be useful if you're more concerned about making sure it's used on iOS and less concerned about the iOS version.
#available here with such a property...! ;]@available attribute then