# `GSGlyph setLayer:forId:`

*Instance Method*

Adds or replaces a layer under an identifier.

## Declaration

```swift
func setLayer(_ layer: GSLayer, forId key: String)
```

```objc
- (void) setLayer:(GSLayer *) layer forId:(NSString *) key;
```

```python
setLayer_forId_(layer: GSLayer, key: str)
```

## Parameters

- `layer` — The layer to add.
- `key` — The layer identifier, or the font master identifier for a master layer.

## Discussion

The layer becomes a child of the glyph and uses the identifier as its [`GSLayer.layerId`](/Core/GlyphsCore/GSLayer/layerId). A font master identifier also becomes the layer’s [`GSLayer.associatedMasterId`](/Core/GlyphsCore/GSLayer/associatedMasterId), making it a master layer. A non-master layer must already identify its associated font master.

## See Also

### Layers

- [`GSGlyph.layers`](/Core/GlyphsCore/GSGlyph/layers) — The layers keyed by their layer identifiers.
- [`GSGlyph sortedLayers`](/Core/GlyphsCore/GSGlyph/sortedLayers) — The layers ordered by font master, with each master layer before the other layers associated with that font master.
- [`GSGlyph countOfLayers`](/Core/GlyphsCore/GSGlyph/countOfLayers) — The number of layers.
- [`GSGlyph objectInLayersAtIndex:`](/Core/GlyphsCore/GSGlyph/objectInLayersAtIndex:) — The layer at an index in insertion order.
- [`GSGlyph layerForId:`](/Core/GlyphsCore/GSGlyph/layerForId:) — The layer for an identifier.
- [`GSGlyph layerForIdFast:`](/Core/GlyphsCore/GSGlyph/layerForIdFast:) — The existing layer for an identifier, or `nil` when the glyph does not contain it.
- [`GSGlyph removeLayerForId:`](/Core/GlyphsCore/GSGlyph/removeLayerForId:) — Removes the layer for an identifier.
- [`GSGlyph layerForName:`](/Core/GlyphsCore/GSGlyph/layerForName:) — The first layer with an exact matching name, or `nil` when no layer matches.
- [`GSGlyph layerForName:masterId:`](/Core/GlyphsCore/GSGlyph/layerForName:masterId:) — The first layer with an exact matching name and associated font master, or `nil` when no layer matches.
- [`GSGlyph layersForName:masterIDs:`](/Core/GlyphsCore/GSGlyph/layersForName:masterIDs:) — One layer for each font master identifier, in the requested order.
- [`GSGlyph layerForKey:masterId:`](/Core/GlyphsCore/GSGlyph/layerForKey:masterId:) — The first layer with a matching derived layer key, or `nil` when no layer matches.
- [`GSGlyph layerNearestToPosition:associatedMasterId:onlyBraceLayer:tolerance:`](/Core/GlyphsCore/GSGlyph/layerNearestToPosition:associatedMasterId:onlyBraceLayer:tolerance:) — The layer nearest to a design-space position within an exclusive distance tolerance, or `nil` when no layer qualifies.
- [`GSGlyph layerAtLocation:ignoring:`](/Core/GlyphsCore/GSGlyph/layerAtLocation:ignoring:) — Returns the layer at the given design space location.
- [`GSGlyph sortLayers:`](/Core/GlyphsCore/GSGlyph/sortLayers:) — Orders layers by font master, placing each master layer before the other layers associated with that font master.
- [`GSGlyph resetLayerKeys`](/Core/GlyphsCore/GSGlyph/resetLayerKeys) — Marks the derived layer keys of all layers for reevaluation.

