简体   繁体   English

SwiftUI UIView 在 scope 中找不到 UIViewRepresentable

[英]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我有一个用 Swift 编写并使用 UIKit 的 iOS 应用程序 我现在决定添加一个手表扩展(配套应用程序)也用 swift 编写,但使用 SwiftUI,而不是 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当我尝试使用 UIViewRepresentable 将 UIKit 视图带入 SwiftUI (UITextView) 时,Xcode 给我一个错误,指出在 scope 中找不到 UIViewRepresentable,它也为结构中的 Context 和 UITextView 提供了相同的错误

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我已经尝试创建一个全新的 SwiftUI 项目,没有链接到应用程序并且它工作正常,没有错误,但是每次我尝试我的手表扩展时,我都会收到上述错误

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.我已经尝试清理构建文件夹并删除派生数据,但都没有成功我已经检查了 SwiftUI 文件的目标并将其设置为监视扩展。 I've also tried closing Xcode and re-opening it, like others have suggested, but still no luck我也试过关闭 Xcode 并重新打开它,就像其他人建议的那样,但仍然没有运气

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?我 go 如何解决这个错误?

thanks in advance提前致谢

I just realised, it's not available in WatchOS我刚刚意识到,它在 WatchOS 中不可用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM