Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Swift says 'any View' cannot conform to 'View'

ErrorType 'any View' cannot conform to 'View'

Short answer

View has an associated type, so a boxed any View value has no single concrete body type and cannot stand in for a generic parameter. Swift only opens the box in simple calls. Use some View or a generic parameter instead of any View, and when a container hides the value, move the work into a generic function.

  • Applies to Swift 6, Xcode 26
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find the line and note whether any View is passed on its own, or wrapped inside an array, an optional or a generic type.

    xcodebuild -scheme MyApp build 2>&1 | grep -B2 -A6 "any View"
  2. 2Match what you see, then jump to its fix

    1. 1The error appears where an any View property or return value meets a generic View parameterA protocol with an associated type is used as a plain value typeFix
    2. 2any View is in [any View], an optional or a generic argumentThe box cannot be opened because it sits inside another typeFix

What does the error look like?

  • Type 'any View' cannot conform to 'View'

Cause 1 of 2

A protocol with an associated type is used as a plain value type

1Check

Per the Swift proposal that introduced any, an existential of a protocol with an associated type cannot conform to the protocol itself, because no concrete associated type fits every value.

grep -rn "any View" Sources/

2Fix

Use a generic parameter or an opaque type, which keep the concrete type known at compile time.

// before
func card(_ content: any View) -> some View { Card(content: content) }
// after
func card<Content: View>(_ content: Content) -> some View { Card(content: content) }

3Verify

The file compiles and the preview renders.

xcodebuild -scheme MyApp build

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 2

The box cannot be opened because it sits inside another type

1Check

Since SE-0352, Swift opens an any value when it is passed directly to a T parameter. It does not open it when T appears in an array, an optional or another generic type, or in a position that returns a type depending on T.

grep -rn "\[any View\]\|any View?" Sources/

2Fix

Move the code that needs the concrete type into a generic function and call it with the element on its own.

func render<V: View>(_ view: V) -> some View {
    view.padding()
}
// call per element, not on the array
render(item)

3Verify

The call compiles because the argument is a single any View value passed straight to a generic parameter.

xcodebuild -scheme MyApp build

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Prefer some View and generic parameters for SwiftUI building blocks.
  • Use any View only where you truly need to store different view types together.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

InstanceID token() no longer works in a Swift Firebase app

Instance ID calls fail to compile after upgrading Firebase to 8.0.0 or later

Firebase removed the Instance ID dependency from Messaging in 8.0.0, so InstanceID.instanceID() calls no longer belong in a current app.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.