---
title: "setSamplerState(_:index:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtlargumentencoder/setsamplerstate(_:index:)"
---

# setSamplerState(_:index:)

Encodes a sampler into the argument buffer.

## Declaration

```swift
func setSamplerState(_ sampler: (any MTLSamplerState)?, index: Int)
```

## Parameters

- `sampler`: A sampler the method encodes.
- `index`: The index of a sampler within the argument buffer. The value corresponds to either the index ID of a declaration in Metal Shading Language (MSL) or the doc://com.apple.metal/documentation/Metal/MTLArgumentDescriptor/index property of an doc://com.apple.metal/documentation/Metal/MTLArgumentDescriptor instance.

## See Also

### Encoding samplers

- [setSamplerStates(_:range:)](metal/mtlargumentencoder/setsamplerstates(_:range:).md)
