7

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?

2
  • Did you quit Xcode or someWhere have defined view class? Commented Dec 4, 2019 at 19:49
  • 1
    Ahh I did indeed have a typealias View = UIView buried somewhere in the code. Could you please add that as an answer, @E.Coms? Commented Dec 4, 2019 at 21:56

1 Answer 1

14

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

Sign up to request clarification or add additional context in comments.

1 Comment

Or there could be a Struct View somewhere. It was in my case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.