0

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?

Alan Spark
  • 8,152
  • 8
  • 56
  • 91
  • 1
    Do you import the framework? I don't see it in your code. ```import SwiftUI``` – La pieuvre Nov 13 '19 at 19:54
  • 1
    That was the problem thanks, I was importing WatchKit in my new file not SwiftUI. – Alan Spark Nov 13 '19 at 19:59
  • In case, when you have a doubt you can go to the documentation (either on Xcode or web) the framework to import is usually stated there : https://developer.apple.com/documentation/swiftui/wkinterfaceobjectrepresentable on the right – La pieuvre Nov 13 '19 at 20:03
  • 1
    Thanks, just getting started with SwiftUI and misunderstood this particular class. I appreciate the tip! – Alan Spark Nov 13 '19 at 20:10
  • No worry, their is always a lot of information to digest when we start with a topic :) – La pieuvre Nov 13 '19 at 20:12

1 Answers1

1

You need to also import SwiftUI:

import SwiftUI

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152