---
title: "How do you fix \"Type cannot conform to View\" in SwiftUI?"
description: "The error means a view body returned something that is not a View. Remove stray statements, return a view from every branch and mark the body some View."
url: "https://bugsee.com/answers/swift/type-cannot-conform-to-view/"
---

# How do you fix "Type cannot conform to View" in SwiftUI?

The `body` (or a closure inside it) produced a value that is not a `View`, often `()` because of a statement such as `print` or an assignment. Return a view from every path.

SwiftUI's builders only accept views. Anything else, including a plain statement that returns nothing, ends up as the type the error complains about.

```swift
// Error: Type '()' cannot conform to 'View'
var body: some View {
    VStack {
        print("rendering")   // a statement is not a view
        Text("Hello")
    }
}

// Fix: run side effects outside the builder, or use a throwaway binding
var body: some View {
    VStack {
        let _ = print("rendering")
        Text("Hello")
    }
    .onAppear { print("appeared") }
}
```

- Make sure the struct really conforms to `View` and that `body` is declared as `some View`.
- Every branch of an `if` or `switch` must produce a view; a branch that returns nothing breaks the type.
- A `ForEach` or `Button` closure that does only work, without returning a label, causes the same message.
- A mistake lower in the file can surface here, so comment out parts of the body until the error moves.

## Related questions

- [How do you use an enum with a Picker in SwiftUI?](https://bugsee.com/answers/swift/swiftui-picker-enum/)
