Implementing Dynamic Island support - Generic parameter 'Expanded' could not be inferred

I'm following Displaying live data with Live Activities and adding support for the Dynamic Island in an app with an existing widgets extension. However, I'm unable too get it to build

import SwiftUI
import WidgetKit


@main
struct PizzaDeliveryActivityWidget: Widget {
    var body: some WidgetConfiguration {
        ActivityConfiguration(for: PizzaDeliveryAttributes.self) { context in
            // Create the presentation that appears on the Lock Screen and as a
            // banner on the Home Screen of devices that don't support the
            // Dynamic Island.
            // ...
        } dynamicIsland: { context in
            // Create the presentations that appear in the Dynamic Island.
            // ...
        }
    }
}

as I get the errors

Generic parameter 'Expanded' could not be inferred

and

Result builder 'DynamicIslandExpandedContentBuilder' does not implement any 'buildBlock' or a combination of 'buildPartialBlock(first:)' and 'buildPartialBlock(accumulated:next:)' with sufficient availability for this call site

This is even if I supply a dynamicIsland closure of

            DynamicIsland {
                EmptyView()
            } compactLeading: {
                EmptyView()
            } compactTrailing: {
                EmptyView()
            } minimal: {
                EmptyView()
            }

What am I missing? My project's minimum deployment target is iOS 16.1.

According to the documentation, the argument expanded in DynamicIsland should implement DynamicIslandExpandedContentBuilder, instead of @ViewBuilder like the remaining others. So, I suggest you implement something like the following snippet:

DynamicIsland {
                // Create the expanded presentation.
                DynamicIslandExpandedRegion(.leading) {
                    EmptyView()
                }
                
                DynamicIslandExpandedRegion(.trailing) {
                    EmptyView()
                }
                
                DynamicIslandExpandedRegion(.bottom) {
                    EmptyView()
                }
            } compactLeading: {
                // Create the compact leading presentation.
                EmptyView()
            } compactTrailing: {
                // Create the compact trailing presentation.
                EmptyView()
            } minimal: {
                // Create the minimal presentation.
                EmptyView()
            }
}

I hope this helps you.

@available(iOS 16.1, *)

Try putting this above the struct.

Implementing Dynamic Island support - Generic parameter 'Expanded' could not be inferred
 
 
Q