# `GSGlyph layerNearestToPosition:associatedMasterId:onlyBraceLayer:tolerance:`

*Instance Method*

The layer nearest to a design-space position within an exclusive distance tolerance, or `nil` when no layer qualifies.

## Declaration

```swift
func layerNearest(toPosition position: UnsafeMutablePointer<CGFloat>, associatedMasterId: String?, onlyBraceLayer: Bool, tolerance: CGFloat) -> GSLayer?
```

```objc
- (GSLayer *) layerNearestToPosition:(CGFloat *) position associatedMasterId:(NSString *) associatedMasterId onlyBraceLayer:(BOOL) onlyBraceLayer tolerance:(CGFloat) tolerance;
```

```python
layerNearestToPosition_associatedMasterId_onlyBraceLayer_tolerance_(position: float, associatedMasterId: str, onlyBraceLayer: bool, tolerance: float) -> GSLayer
```

## Parameters

- `position` — A buffer containing one internal coordinate for each font axis, in font axis order.
- `associatedMasterId` — The required associated font master identifier, or `nil` to consider all layers.
- `onlyBraceLayer` — Whether to consider only Intermediate layers.
- `tolerance` — The exclusive maximum Euclidean distance from `position`.

## 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 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 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.

