In Xcode I am having issues between watchOS and iOS. The following code is the same for both targets:
watchOS
class ExtensionDelegate: NSObject, WKExtensionDelegate {
var variable1: Float?
}
iOS
class AppDelegate: UIResponder, UIApplicationDelegate {
var variable1: Float?
}
the class
class SomeClass: ObservableObject {
#if os(iOS)
let delegate = UIApplication.shared.delegate as! AppDelegate
#elseif os(watchOS)
let delegate = WKExtension.shared().delegate as! WKExtension
#endif
func somefunc(){
delegate.variable1 = 0.0 // Fine when target is iOS, fails when watchOS with WKExtension has no member variable1
}
}
I am not sure why that delegate.variable1 is invalid for watchOS but not iOS