<!--
{
  "availability" : [
    "iOS: 2.0.0 - 27.0.0",
    "iPadOS: 2.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 10.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/XMLElement/setAttributesAs(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXMLElement(im)setAttributesAsDictionary:"
  },
  "title" : "setAttributesAs(_:)"
}
-->

# setAttributesAs(_:)

Sets the attributes of the receiver based on the key-value pairs specified in the passed-in dictionary.

```
func setAttributesAs(_ attributes: [AnyHashable : Any])
```

## Parameters

`attributes`

A dictionary of key-value pairs where the attribute name is the key and the object value of the attribute is the dictionary value.

## Discussion

The method uses these names and object values to create [`XMLNode`](/documentation/Foundation/XMLNode) objects of kind [`XMLNode.Kind.attribute`](/documentation/Foundation/XMLNode/Kind-swift.enum/attribute). Existing attributes are not removed.

---

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)