问题描述
我正在采用WatchConnectivity,但是我仍支持没有该库的iOS7和iOS 8.而且我采用的协议WCSessionDelegate也不受支持,但是这个较旧的系统.在ObjectiveC中,我将使用预处理指令来屏蔽此声明和不支持它们的版本所采用的协议.如何在Swift中处理该问题,以使该应用程序不会在较旧的系统上崩溃?
I am adopting WatchConnectivity, but I am still supporting iOS7 and iOS 8 for which this library is not available. Moreover I am adopting protocol WCSessionDelegate also not supported but this older systems.In ObjectiveC I would have used preprocessing directives to shield this declaration and the protocol adoption from versions not supporting them. How do I handle that in Swift so that the app does not crash on older systems?
推荐答案
我感谢@joern在委托中采用协议的建议,在此我进行总结:
I thank @joern for the suggestion of adopting the protocol in a delegate which I here summarize:
@available(iOS 9, *)
extension inArrivoHDAppDelegate: WCSessionDelegate {}
这篇关于在Swift中检查协议可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!