I declared a failable initializer in my 'HealthKitService' which is, as the name says, a utility class for HealthKit. The problem is that certain HealthKit classes such as HKWorkoutSession, are available for Watch OS only, so I had to use a preprocessor directive to make a function available for Watch OS only:
#if TARGET_OS_WATCH
init?(activity:String) {
// Here I initialize my HKWorkoutSession object
}
#endif
But if I call this initializer from the WatchKit extension app, this way:
if let service = HealthKitService(activity: activity) {
// Do something with it
}
I receive this error:
Cannot invoke initializer for type 'HealthKitService' with an argument list of type '(activity: String)'
PS: The deployment target is Watch OS 3.2, Swift version: 3.
Try #if os(watchOS)
instead of #if TARGET_OS_WATCH
.