<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/AttributeContainer/init(_:including:)-28n0g",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation18AttributeContainerV_9includingACSDySo21NSAttributedStringKeyaypG_s0G4PathCyAA0B6ScopesOxmGtKcAA0B5ScopeRzlufc"
  },
  "title" : "init(_:including:)"
}
-->

# init(_:including:)

Creates an attribute container from a dictionary and an attribute scope that a key path identifies.

```
init<S>(_ dictionary: [NSAttributedString.Key : Any], including scope: KeyPath<AttributeScopes, S.Type>) throws where S : AttributeScope
```

## Parameters

`dictionary`

A dictionary of attribute keys and their values.

`scope`

A key path that identifies the attribute scope of the dictionary keys. This can be a nested scope that contains several scopes.

## Discussion

This initializer only collects attributes from `dictionary` that exist in the provided scope. The resulting attribute container omits any keys in `dictionary` that don’t exist in `scope`.

---

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)