# `GSLayer setAttribute:forKey:`

*Instance Method*

Sets or removes an attribute.

## Declaration

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

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

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

## Parameters

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

## Discussion

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

## See Also

### Attributes

- [`GSLayer.attributes`](/Core/GlyphsCore/GSLayer/attributes) — Values that configure layer behavior and special layer formats.
- [`GSLayer countOfAttributes`](/Core/GlyphsCore/GSLayer/countOfAttributes) — The number of attributes.
- [`GSLayer attributeForKey:`](/Core/GlyphsCore/GSLayer/attributeForKey:) — The value for an attribute key, or `nil` if no value is set.
- [`GSLayer setAttributesFast:`](/Core/GlyphsCore/GSLayer/setAttributesFast:) — Replaces all attributes without registering undo or notifying the glyph.
- [`GSLayer setAttributeFast:forKey:`](/Core/GlyphsCore/GSLayer/setAttributeFast:forKey:) — Sets an attribute without registering undo or notifying the glyph.
- [`GSLayer removeAttributeForKey:`](/Core/GlyphsCore/GSLayer/removeAttributeForKey:) — Removes an attribute.

