jamie hancock
jamie hancock

Reputation: 173

SwiftUI UIView UIViewRepresentable not found in scope

I have an iOS app written in Swift and using UIKit I have now decided to add a watch extension (companion app) also written in swift, but using SwiftUI, instead of UIKit

When I try to bring a UIKit view into SwiftUI (UITextView) using UIViewRepresentable, Xcode gives me an error saying that UIViewRepresentable is not found in scope, it also gives the same error for Context and UITextView in the struct

I've tried creating a brand new SwiftUI project, not linked to an app and it works fine, with no errors, but every time I try on my watch extension, I get the above error

I've tried cleaning the build folder and deleting derived data, both with no luck I've checked the target of the SwiftUI file and it is set to watch extension. I've also tried closing Xcode and re-opening it, like others have suggested, but still no luck

here is my struct that causes the error

struct TextView: UIViewRepresentable { <-- error here (UIViewRepresentable not found in scope)    

@Binding var text: NSMutableAttributedString

func makeUIView(context: Context) -> UITextView { <-- error here (context and UITextView not found in scope)
    UITextView()
}

func updateUIView(_ uiView: UITextView, context: Context) {<-- error here (context and UITextView not found in scope)
    uiView.attributedText = text
}

}

how would I go about resolving this error?

thanks in advance

Upvotes: 2

Views: 1972

Answers (2)

user3413723
user3413723

Reputation: 12263

I had this problem because I created a universal app. Click on the little folder in the top left. Then click your app icon. then under the page that shows up, under "Project", click the app icon. Then under General -> supported destinations, you have to remove mac and it seems to work now.

Upvotes: 0

jamie hancock
jamie hancock

Reputation: 173

I just realised, it's not available in WatchOS

Upvotes: 2

Related Questions