# `GSGlyph.layers`

*Instance Property*

The layers keyed by their layer identifiers.

## Declaration

```swift
var layers: [String : GSLayer] { get set }
```

```objc
@property (nonatomic, strong) NSDictionary<NSString *,GSLayer *> * layers;
```

[See also `layers` in the Python API](https://docu.glyphsapp.com/#GSGlyph.layers)

```python
pyobjc_instanceMethods.layers() -> dict[str, GSLayer]
pyobjc_instanceMethods.setLayers_(layers: dict[str, GSLayer])
```

## Discussion

A glyph in a font normally has one master layer for each font master and can contain additional Intermediate, Alternative, color, and backup layers. A master layer uses its font master identifier as both its [`GSLayer.layerId`](/Core/GlyphsCore/GSLayer/layerId) and [`GSLayer.associatedMasterId`](/Core/GlyphsCore/GSLayer/associatedMasterId). Other layers use a distinct [`GSLayer.layerId`](/Core/GlyphsCore/GSLayer/layerId) and identify the font master that supplies master-specific values through [`GSLayer.associatedMasterId`](/Core/GlyphsCore/GSLayer/associatedMasterId).

Layer indexes use the collection’s insertion order. Use [`GSGlyph sortedLayers`](/Core/GlyphsCore/GSGlyph/sortedLayers) for font master order and [`GSGlyph setLayer:forId:`](/Core/GlyphsCore/GSGlyph/setLayer:forId:) or [`GSGlyph removeLayerForId:`](/Core/GlyphsCore/GSGlyph/removeLayerForId:) for individual changes. Do not modify the returned dictionary directly because this bypasses layer ownership, undo, and notifications. When assigning the complete collection, each key must match the corresponding [`GSLayer.layerId`](/Core/GlyphsCore/GSLayer/layerId).

## See Also

### Layers

- [`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 setLayer:forId:`](/Core/GlyphsCore/GSGlyph/setLayer:forId:) — Adds or replaces a layer under an identifier.
- [`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.

