RSDActiveUIStepObject

open class RSDActiveUIStepObject : RSDUIStepObject, RSDActiveUIStep

RSDActiveUIStepObject extends the RSDUIStepObject to include a duration and commands. This is used for the case where an RSDUIStep has an action such as start walking or stop walking; the step may also implement the RSDActiveUIStep protocol to allow for spoken instruction.

  • The duration of time to run the step. If 0, then this value is ignored.

    Declaration

    Swift

    public var duration: TimeInterval = 0
  • The set of commands to apply to this active step. These indicate actions to fire at the beginning and end of the step such as playing a sound as well as whether or not to automatically start and finish the step.

    Seealso

    RSDActiveUIStepCommand.stringMapping for a list of the coding strings included in this framework.

    Declaration

    Swift

    public var commands: RSDActiveUIStepCommand = .defaultCommands
  • Whether or not the step uses audio, such as the speech synthesizer, that should play whether or not the user has the mute switch turned on. Default = false.

    Declaration

    Swift

    public var requiresBackgroundAudio: Bool = false
  • A mapping of the localized text that represents an instructional voice prompt to the time marker for speaking the instruction.

    The mapping is Codable using either TimeInterval values as the keys or by using the SpokenInstructionKeys as special keys into the mapping dictionary.

    • example:

          // Example JSON dictionary that includes a spoken instruction map.
          let json = """
          {
             "identifier": "foo",
             "type": "active",
             "title": "Hello World!",
             "text": "Some text.",
             "duration": 30,
             "requiresBackgroundAudio": true,
             "commands": ["playSoundOnStart", "vibrateOnFinish"],
             "spokenInstructions" : { "start": "Start moving",
                                      "10": "Keep going",
                                      "halfway": "Halfway there",
                                      "countdown": "5",
                                      "end": "Stop moving"}
          }
          """.data(using: .utf8)! // our data in native (JSON) format
      
          // The decoded mapping.
          self.spokenInstructions = [ 0.0 : "Start moving",
                                      10.0 : "Keep going",
                                      15.0 : "Halfway there",
                                      25.0 : "five",
                                      26.0 : "four",
                                      27.0 : "three",
                                      28.0 : "two",
                                      29.0 : "one",
                                      Double.infinity : "Stop moving"]
      

    Declaration

    Swift

    public var spokenInstructions: [TimeInterval : String]?
  • The SpokenInstructionKeys are specialized markers for the timing of when to speak the spoken instruction. These include keys that can be transformed into a time interval using the duration of the step to indicate the halfway point.

    See more

    Declaration

    Swift

    public enum SpokenInstructionKeys : String, CodingKey
  • Localized text that represents an instructional voice prompt. Instructional speech begins when the step passes the time indicated by the given time. If timeInterval is greater than or equal to duration or is equal to Double.infinity, then the spoken instruction returned should be for when the step is finished.

    Declaration

    Swift

    open func spokenInstruction(at timeInterval: TimeInterval) -> String?

    Parameters

    timeInterval

    The time interval at which to speak the instruction.

    Return Value

    The localized instruction to speak or nil if there isn’t an instruction.

  • Default initializer.

    Declaration

    Swift

    public override init(identifier: String, type: RSDStepType? = nil)

    Parameters

    identifier

    A short string that uniquely identifies the step.

    type

    The type of the step. Default = RSDStepType.active

  • Initialize from a Decoder.

  • example:

        // Example JSON dictionary that includes a duration, commands, and spoken instruction mapping.
        let json = """
        {
           "identifier": "foo",
           "type": "active",
           "title": "Hello World!",
           "text": "Some text.",
           "duration": 30,
           "commands": ["playSoundOnStart", "vibrateOnFinish"],
           "spokenInstructions" : { "start": "Start moving",
                                    "10": "Keep going",
                                    "halfway": "Halfway there",
                                    "countdown": "5",
                                    "end": "Stop moving"}
        }
        """.data(using: .utf8)! // our data in native (JSON) format
    
    
  • Throws

    DecodingError

    Declaration

    Swift

    public required init(from decoder: Decoder) throws

    Parameters

    decoder

    The decoder to use to decode this instance.

  • A step to merge with this step that carries replacement info. This step will look at the replacement info in the generic step and replace properties on self as appropriate.

    For an RSDActiveUIStepObject, the duration property can be replaced.

    Declaration

    Swift

    open override func replace(from step: RSDGenericStep) throws