---
title: "objc_setAssociatedObject(_:_:_:_:)"
framework: Objective-C Runtime
role: symbol
role_heading: Function
platforms: [iOS 3.1+, iPadOS 3.1+, Mac Catalyst 13.1+, macOS 10.6+, tvOS 9.0+, visionOS 1.0+, watchOS 1.0+]
path: "objectivec/objc_setassociatedobject(_:_:_:_:)"
---

# objc_setAssociatedObject(_:_:_:_:)

Sets an associated value for a given object using a given key and association policy.

## Declaration

```swift
func objc_setAssociatedObject(_ object: Any, _ key: UnsafeRawPointer, _ value: Any?, _ policy: objc_AssociationPolicy)
```

## Parameters

- `object`: The source object for the association.
- `key`: The key for the association.
- `value`: The value to associate with the key key for object. Pass nil to clear an existing association.
- `policy`: The policy for the association. For possible values, see doc://com.apple.objectivec/documentation/ObjectiveC/objc_AssociationPolicy.

## See Also

### Associative References

- [objc_getAssociatedObject(_:_:)](objectivec/objc_getassociatedobject(_:_:).md)
- [objc_removeAssociatedObjects(_:)](objectivec/objc_removeassociatedobjects(_:).md)
