Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI View starter code complains about `inheritance from non-protocol type 'View'` when added to an existing project

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:

enter image description here

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?

like image 362
Senseful Avatar asked Dec 17 '22 14:12

Senseful


1 Answers

It seems to us there is a typealias View = UIView some where to mess the View with UIView.

like image 60
E.Coms Avatar answered May 10 '23 13:05

E.Coms