---
title: "setValue(_:forCustomKey:)"
framework: corespotlight
role: symbol
role_heading: Instance Method
path: "corespotlight/cssearchableitemattributeset/setvalue(_:forcustomkey:)"
---

# setValue(_:forCustomKey:)

Sets the value for a custom attribute key.

## Declaration

```swift
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.

## See Also

### Accessing custom attributes

- [value(forCustomKey:)](corespotlight/cssearchableitemattributeset/value(forcustomkey:).md)
