<!--
{
  "availability" : [
    "iOS: 8.0.0 - 26.0.0",
    "iPadOS: 8.0.0 - 26.0.0",
    "macCatalyst: 13.1.0 - 26.0.0",
    "macOS: 10.8.0 - 26.0.0",
    "tvOS: 9.0.0 - 26.0.0",
    "visionOS: 1.0.0 - 26.0.0",
    "watchOS: 3.0.0 - 26.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "SceneKit",
  "identifier" : "/documentation/SceneKit/SCNLight/setAttribute(_:forKey:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SceneKit"
    ],
    "preciseIdentifier" : "c:objc(cs)SCNLight(im)setAttribute:forKey:"
  },
  "title" : "setAttribute(_:forKey:)"
}
-->

# setAttribute(_:forKey:)

Sets the value for a lighting attribute.

```
func setAttribute(_ attribute: Any?, forKey key: String)
```

## Parameters

`attribute`

The value for the lighting attribute.

`key`

A constant specifying a lighting attribute. See [Lighting Attribute Keys](/documentation/SceneKit/lighting-attribute-keys) for available keys and their possible values.

## Discussion

A light’s [`type`](/documentation/SceneKit/SCNLight/type) property determines its set of available attributes.

You can also set or animate changes to the values of lighting attributes using [Key-value coding](https://developer.apple.com/library/archive/documentation/General/Conceptual/DevPedia-CocoaCore/KeyValueCoding.html#//apple_ref/doc/uid/TP40008195-CH25). The key path for each lighting attribute is listed in [Lighting Attribute Keys](/documentation/SceneKit/lighting-attribute-keys).

---

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)