<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FoundationModels",
  "identifier" : "/documentation/FoundationModels/GeneratedContent/init(properties:id:uniquingKeysWith:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation Models",
      "FoundationModels"
    ],
    "preciseIdentifier" : "s:16FoundationModels16GeneratedContentV10properties2id16uniquingKeysWithACx_AA12GenerationIDVSgq_AC_ACtKXEtKcSTRzAA013ConvertibleTocD0R_SS_AaJ_pt7ElementRtzr0_lufc"
  },
  "title" : "init(properties:id:uniquingKeysWith:)"
}
-->

# init(properties:id:uniquingKeysWith:)

Creates generated content from key-value pairs, resolving duplicate keys with a combining closure.

```
init<S>(properties: S, id: GenerationID? = nil, uniquingKeysWith combine: (GeneratedContent, GeneratedContent) throws -> some ConvertibleToGeneratedContent) rethrows where S : Sequence, S.Element == (String, any ConvertibleToGeneratedContent)
```

## Parameters

`properties`

A sequence of key-value pairs to use for the new content.

`id`

A unique id associated with [`GeneratedContent`](/documentation/FoundationModels/GeneratedContent).

`combine`

A closure that is called with the values to resolve any duplicates
keys that are encountered. The closure returns the desired value for the final content.

## Discussion

The order of properties is important. For [`Generable`](/documentation/FoundationModels/Generable) types, the order
must match the order properties in the types `schema`.

You use this initializer to create generated content when you have a sequence
of key-value tuples that might have duplicate keys. As the content is
built, the initializer calls the `combine` closure with the current and
new values for any duplicate keys. Pass a closure as `combine` that
returns the value to use in the resulting content: The closure can
choose between the two values, combine them to produce a new value, or
even throw an error.

The following example shows how to choose the first and last values for
any duplicate keys:

```swift
    let content = GeneratedContent(
      properties: [("name", "John"), ("name", "Jane"), ("married", true)],
      uniquingKeysWith: { (first, _) in first }
    )
    // GeneratedContent(["name": "John", "married": true])
```

---

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)