# `GSBaseObject setAttribute:forKey:`

*Instance Method*

Sets or removes an attribute.

## Declaration

```swift
func setAttribute(_ value: Any?, forKey key: GSShapeKey)
```

```objc
- (void) setAttribute:(id) value forKey:(GSShapeKey) key;
```

```python
setAttribute_forKey_(value: object, key: GSShapeKey)
```

## Parameters

- `value` — A value that supports property-list encoding, or `nil` to remove the attribute.

## Discussion

Setting an attribute registers undo and notifies the parent. Passing `nil` as the value removes the attribute.

## See Also

### Attributes

- [`GSBaseObject.attributes`](/Core/GlyphsCore/GSBaseObject/attributes) — Additional values associated with the object.
- [`GSBaseObject.countOfAttributes`](/Core/GlyphsCore/GSBaseObject/countOfAttributes) — The number of attributes.
- [`GSBaseObject attributeForKey:`](/Core/GlyphsCore/GSBaseObject/attributeForKey:) — The value for an attribute key, or `nil` if no value is set.
- [`GSBaseObject setAttributes:format:`](/Core/GlyphsCore/GSBaseObject/setAttributes:format:) — Replaces all attributes using values encoded for a file format version.
- [`GSBaseObject setAttributesFast:format:`](/Core/GlyphsCore/GSBaseObject/setAttributesFast:format:) — Replaces all attributes without registering undo or notifying the parent.
- [`GSBaseObject removeAttributeForKey:`](/Core/GlyphsCore/GSBaseObject/removeAttributeForKey:) — Removes an attribute.

