Xcode 11 Beta 3, build error “Unknown attribute 'State'”, “Use of undeclared type 'View'” etc

こ雲淡風輕ζ 提交于 2020-01-20 08:38:12

问题


I build an app with the 2nd beta of Xcode 11, using SwiftUI, and everything worked completely fine, but now, with the 3rd beta, the app isn't even build. I get errors like "Use of undeclared type 'View'", "Unknown attribute 'State'" etc. What can I do? Is the problem in my code or is it just a bug?

The problem is when I'm trying to build the app to run on my Mac (with UIKit for Mac)

@State var score = 0

The error is "Unknown attribute 'State'"

struct ContentView : View {
    /*...*/
}

The error is "Use of undeclared type 'View'"


回答1:


This is from the Xcode 11 Beta 3 Release Notes.

Known Issues

  • Xcode 11 doesn’t support working with SwiftUI in an iPad app brought to macOS. (41416222, 51201699)

I downloaded the Xcode 11 Beta 3 myself just to confirm the errors you mentioned, and I had the same issues when trying to build a SwiftUI project for Mac.

I would suggest going back to using Xcode Beta 2 if possible. Unfortunately, Apple doesn't provide download links to previous betas, so hopefully you have a Time Machine backup or Beta 2 still installed on your computer. Otherwise, you might be out of luck until the next beta is released.




回答2:


I was getting the same "Unknown attribute 'State'" issue in Beta 5. But I was doing "@state" and not "@State". Case matters. It's hard to notice because both ways are shown as purple.




回答3:


Got same issue on Xcode 11.2. Found out that the reason was that somewhere in same module I declared protocol State {}. This breaks compiler without any reasonable errors.



来源:https://stackoverflow.com/questions/56967198/xcode-11-beta-3-build-error-unknown-attribute-state-use-of-undeclared-typ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!