Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 284
jamie hancock Avatar asked Nov 16 '25 09:11

jamie hancock


1 Answers

I just realised, it's not available in WatchOS

like image 79
jamie hancock Avatar answered Nov 18 '25 19:11

jamie hancock



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!