I have an existing Xcode project. I need to create a new view. I was going to use File > New > File... > View, but then I noticed there is another option SwiftUI View
. So I decided to give it a shot. I went ahead and chose SwiftUI View.
It created the following starter code:
import SwiftUI
struct FooBar: View {
var body: some View {
Text("Hello, World!")
}
}
struct FooBar_Previews: PreviewProvider {
static var previews: some View {
FooBar()
}
}
And it has the following compiler errors:
I tried cleaning, and selecting the iPhone 11 Pro simulator as the destination target, but it still has the same compiler errors.
For search-ability, here are all the errors:
- Inheritance from non-protocol type 'View' (aka 'UIView')
- Function declares an opaque return type, but has no return statements in its body from which to infer an underlying type
- Cannot convert return expression of type 'Text' to return type 'some View'
- Type 'FooBar_Previews' does not conform to protocol 'PreviewProvider'
- Function declares an opaque return type, but has no return statements in its body from which to infer an underlying type
- Cannot convert return expression of type 'FooBar' to return type 'some View'
I'm on macOS Catalina, Xcode 11.2.1, and the deployment target is iOS 13.0.
What am I doing wrong?
It seems to us there is a typealias View = UIView
some where to mess the View
with UIView
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With