SmartSpectra SDK
Swift

Configuring Metrics

Request and read SmartSpectra metrics from the Swift SDK.

By default, Swift SDK measurements request the breathing metric set. Add pulse rate when your app needs a basic cardio value.

Breathing and Pulse

Request Metrics

Request the default breathing metrics plus .pulseRate before calling start():

import SmartSpectra

let sdk = SmartSpectraSDK.shared
sdk.config.requestedMetrics = SmartSpectraConfig.breathingMetrics + [.pulseRate]

Read Metrics

Read the latest breathing and pulse samples from SmartSpectraSDK.metrics:

private let sdk = SmartSpectraSDK.shared

if let metrics = sdk.metrics {
    let breathingRate = metrics.breathing.rate.last?.value
    let chestTrace = metrics.breathing.upperTrace.last?.value
    let abdomenTrace = metrics.breathing.lowerTrace.last?.value
    let pulseRate = metrics.cardio.pulseRate.last?.value
}

Set requestedMetrics = nil to return to the default breathing-only set. Cardio fields are empty unless you request a cardio metric such as .pulseRate.

Advanced

Request additional metrics only when your app needs them:

sdk.config.requestedMetrics = SmartSpectraConfig.breathingMetrics + [
    .pulseRate,
    .arterialPressureTrace,
    .hrv,
    .edaTrace,
    .faceLandmarks,
    .blinking,
    .talking,
    .expressions,
    .glutesMicromotion,
    .kneesMicromotion,
]

Read the advanced fields from the same metrics object:

if let metrics = sdk.metrics {
    let pressureTrace = metrics.cardio.arterialPressureTrace.last?.value
    let hrvRmssd = metrics.cardio.hrv.last?.rmssd

    let edaTrace = metrics.eda.trace.last?.value

    let faceLandmarks = metrics.face.landmarks.last?.value
    let blinking = metrics.face.blinking.last?.detected
    let talking = metrics.face.talking.last?.detected
    let expression = metrics.face.expression.last

    let glutesMotion = metrics.micromotion.glutes.last?.value
    let kneesMotion = metrics.micromotion.knees.last?.value
}

Advanced Payload Types

The Swift SDK uses the generated Swift protobuf types. Requested advanced metrics populate these fields:

Metrics {
    breathing: Breathing
    micromotion: MicroMotion
    eda: Eda
    face: Face
    cardio: Cardio
}

Cardio {
    pulseRate: [MeasurementWithConfidence]
    arterialPressureTrace: [MeasurementWithConfidence]
    hrv: [Hrv]
}

Hrv {
    rmssd: Double
    meanNn: Double
    sdnn: Double
    baevsky: Double
    timestamp: Int64
    confidence: Float
}

Eda {
    trace: [Measurement]
}

Face {
    landmarks: [Landmarks]
    blinking: [DetectionStatus]
    talking: [DetectionStatus]
    expression: [Expression]
}

MicroMotion {
    glutes: [Measurement]
    knees: [Measurement]
}

EDA may take longer to produce its first sample than breathing or cardio outputs. See Data Types for the complete protobuf schema.

On this page