<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreSpotlight",
  "identifier" : "/documentation/CoreSpotlight/CSSearchableItemAttributeSet/setValue(_:forCustomKey:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Spotlight",
      "CoreSpotlight"
    ],
    "preciseIdentifier" : "c:objc(cs)CSSearchableItemAttributeSet(im)setValue:forCustomKey:"
  },
  "title" : "setValue(_:forCustomKey:)"
}
-->

# setValue(_:forCustomKey:)

Sets the value for a custom attribute key.

```
func setValue(_ value: (any NSSecureCoding)?, forCustomKey key: CSCustomAttributeKey)
```

## Parameters

`value`

The value of the custom attribute. Values must be common property list types, such as <doc://com.apple.documentation/documentation/Foundation/NSString>, <doc://com.apple.documentation/documentation/Foundation/NSNumber>, <doc://com.apple.documentation/documentation/Foundation/NSNull>, <doc://com.apple.documentation/documentation/Foundation/NSData>, or <doc://com.apple.documentation/documentation/Foundation/NSDate>, or an array of property list types.

`key`

The custom attribute key.

---

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)