On iOS you can call setPreferredSampleRate(_:) then check whether the requested change took effect.
On macOS you can get the ID of the underlying Core Audio device from an AVAudioIONode, and get and set the device's sample rate using the kAudioDevicePropertyNominalSampleRate selector. You can similarly get a list of sample rates the device supports using the kAudioDevicePropertyAvailableNominalSampleRates selector. Below is an example:
// initialize the input node and store the device ID
let inputNode = engine.inputNode
let device = inputNode.auAudioUnit.deviceID
// get the list of available sample rates
var address = AudioObjectPropertyAddress()
address.mSelector = kAudioDevicePropertyAvailableNominalSampleRates
address.mScope = kAudioObjectPropertyScopeGlobal
address.mElement = kAudioObjectPropertyElementMain
var size = UInt32.zero
assert(AudioObjectGetPropertyDataSize(device, &address, 0, nil, &size) == noErr)
let count = size / UInt32(MemoryLayout<AudioValueRange>.stride)
var valueRanges = [AudioValueRange](repeating: .init(), count: Int(count))
assert(AudioObjectGetPropertyData(device, &address, 0, nil, &size, &valueRanges) == noErr)
// print the available sample rates
for valueRange in valueRanges {
print(valueRange.mMaximum)
}
// set the sample rate
address.mSelector = kAudioDevicePropertyNominalSampleRate
size = UInt32(MemoryLayout<Double>.stride)
var sampleRate = valueRanges.last?.mMaximum ?? 48000.0
assert(AudioObjectSetPropertyData(device, &address, 0, nil, size, &sampleRate) == noErr)
// get the current sample rate and print it
assert(AudioObjectGetPropertyData(device, &address, 0, nil, &size, &sampleRate) == noErr)
print(sampleRate)
try? engine.start()