<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/WindowGroup/init(_:id:for:content:defaultValue:)-95crv",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI11WindowGroupV_2id3for7content12defaultValueACyAA09PresentedC7ContentVyqd__qd_0_GGAA18LocalizedStringKeyV_SSqd__mqd_0_AA7BindingVyqd__Gcqd__yctcAJRszSeRd__SERd__SHRd__AA4ViewRd_0_r0_lufc"
  },
  "title" : "init(_:id:for:content:defaultValue:)"
}
-->

# init(_:id:for:content:defaultValue:)

Creates a data-presenting window group with a localized title
string, an identifier, and a default value.

```
nonisolated init<D, C>(_ titleKey: LocalizedStringKey, id: String, for type: D.Type = D.self, @ContentBuilder content: @escaping (Binding<D>) -> C, defaultValue: @escaping () -> D) where Content == PresentedWindowContent<D, C>, D : Decodable, D : Encodable, D : Hashable, C : View
```

## Parameters

`titleKey`

The title key to use for the group’s title.

`id`

A string that uniquely identifies the window group. Identifiers
must be unique among the window groups in your app.

`type`

The type of presented data this window group accepts.

`content`

A closure that creates the content for each instance
of the group. The closure receives a binding to the value that you
pass into the `EnvironmentValues/openWindow` action when you open
the window. SwiftUI automatically persists and restores the value
of this binding as part of the state restoration process.

`defaultValue`

A closure that returns a default value to present.
SwiftUI calls this closure when it has no data to provide, like
when someone opens a new window from the File > New Window menu
item.

## Discussion

The window group uses the specified content as a
template to create each window in the group.

The system uses the title to distinguish the window group in the user
interface, such as in the name of commands associated with the group.

SwiftUI creates a window from the group when you present a value
of the specified type using the `EnvironmentValues/openWindow` action.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)