Alan Spark
Alan Spark

Reputation: 8312

Why are WatchKit classes not recognised in new .swift file?

I am trying to create a new swift file in Xcode to house a class that derives from WKInterfaceObjectRepresentable. E.g.

import WatchKit

struct Bing: WKInterfaceObjectRepresentable {
}

But I get the following error:

Use of undeclared type 'WKInterfaceObjectRepresentable'

However, if I add it to one of the standard files (ContentView.swift) it picks it up correctly.

I thought it might be to do with the target membership but it is exactly the same for my new Bing.swift as it is for ContentView.swift (WatchKit Extension).

Any ideas?

Upvotes: 0

Views: 184

Answers (1)

Daniel Storm
Daniel Storm

Reputation: 18908

You need to also import SwiftUI:

import SwiftUI

Upvotes: 1

Related Questions