RSDTaskViewModel

open class RSDTaskViewModel : RSDTaskState, RSDTaskPathComponent

The TaskViewModel is a base class implementation of the presentation layer for managing a task. It uses the Model–view–viewmodel (MVVM) design pattern to separate out the UX functionality of running a task for a given device category from the UI and from the domain layer.

This class is used to keep track of the current state of a running task. Conceptually, it is a similar pattern to using a separate device-agnostic DataSource class to handle UX that is independent of the operating system and which can be used by either a UIViewController on iOS and tvOS or a WKInterface on watchOS.

The naming convention used is intended to ease cross-platform development with an Android app since on that platform, there are significant advantages to using a Fragment-ViewModel architecture where the base class is a ViewModel rather than an NSObject. The implementation details of this class and the method names will differ from the Android architecture to fit the design patterns which are more common to Swift and Obj-c development.

  • A unique identifier for this path component.

    Declaration

    Swift

    open private(set) var identifier: String {
      get
      }
  • The task info object used to load the task.

    Declaration

    Swift

    public private(set) var taskInfo: RSDTaskInfo? {
      get
      }
  • The task that is currently being run.

    Declaration

    Swift

    public private(set) var task: RSDTask? {
      get
      }
  • The data manager for accessing previous runs of the task.

    Declaration

    Swift

    public weak var dataManager: RSDDataStorageManager? { get set }
  • Should the task only display an abbreviated set of instruction steps?

    Declaration

    Swift

    open var shouldShowAbbreviatedInstructions: Bool?
  • A weak pointer to the task controller.

    Declaration

    Swift

    public var taskController: RSDTaskController? { get set }
  • The description of the path.

    Declaration

    Swift

    override open var description: String { get }
  • The design system to use for this task.

    Declaration

    Swift

    open var designSystem: RSDDesignSystem { get }
  • Initialize the task path with a task.

    Declaration

    Swift

    public init(task: RSDTask, parentPath: RSDPathComponent? = nil)

    Parameters

    task

    The task to set for this path segment.

    parentPath

    A pointer to the parent task path.

  • Initialize the task path with a task.

    Declaration

    Swift

    public init(taskInfo: RSDTaskInfo, parentPath: RSDPathComponent? = nil)

    Parameters

    taskInfo

    The task info to set for this path segment.

    parentPath

    A pointer to the parent task path.

  • The current child that this component is pointing to.

    Declaration

    Swift

    public var currentChild: RSDNodePathComponent?
  • The parent path component. If nil, this is the top-level path component.

    Declaration

    Swift

    weak public internal(set) var parent: RSDPathComponent? {
      get
      }
  • Convenience method for accessing the current step.

    Declaration

    Swift

    open var currentStep: RSDStep? { get }
  • Can this task go forward? If forward navigation is enabled, then the task isn’t waiting for a result or a task fetch to enable forward navigation.

    Declaration

    Swift

    open var isForwardEnabled: Bool { get }
  • Can the path navigate backward up the chain?

    Declaration

    Swift

    open var canNavigateBackward: Bool { get }
  • Declaration

    Swift

    override open var outputDirectory: URL! { get set }
  • The result to use to mark the step history for this path component.

    Declaration

    Swift

    open func pathResult() -> RSDResult
  • Perform the appropriate action.

    Declaration

    Swift

    open func perform(actionType: RSDUIActionType)
  • Should the step view controller confirm the cancel action? By default, this will return false if this is the first step in the task. Otherwise, this method will return true.

    Declaration

    Swift

    open func shouldConfirmCancel() -> Bool

    Return Value

    Whether or not to confirm the cancel action.

  • Can the task progress be saved? This should only return true if the task result can be saved and the current progress can be restored.

    Declaration

    Swift

    open func canSaveTaskProgress() -> Bool
  • This is a flag that can be used to mark whether or not the task is ready to be saved.

    Declaration

    Swift

    open internal(set) var isCompleted: Bool {
      get
      }
  • This is a flag that can be used to mark whether or not the task exited early.

    Declaration

    Swift

    open internal(set) var didExitEarly: Bool {
      get
      }
  • Is there a next step or is this the last step in the task?

    Declaration

    Swift

    public var hasStepAfter: Bool { get }
  • Is there previous step that this task can go back to?

    Declaration

    Swift

    public var hasStepBefore: Bool { get }
  • Go forward to the next step. If the task is not loaded for the current point in the task path, then it will attempt to fetch it again.

    Declaration

    Swift

    open func goForward()
  • Go back to the previous step.

    Declaration

    Swift

    open func goBack()
  • Call through to the task controller to handle the task finished with a reason of .cancelled.

    Declaration

    Swift

    open func cancel(shouldSave: Bool = false)
  • Start the task if it is not currently loaded with a task or first step.

    Declaration

    Swift

    open func startTaskIfNeeded()
  • For the given step, returns the next path component and step controller (if applicable) for this step. The base class implementation will return an RSDTaskStepNode for either a subtask step or a section step. For all other steps, it will request a step controller for the step from the task controller and return both the step controller and the loaded step view model as the node.

    Declaration

    Swift

    open func pathComponent(for step: RSDStep) -> (node: RSDNodePathComponent, stepController: RSDStepController?)?
  • Overridable factory method for returning a hidden task step node to use in subtask navigation.

    Declaration

    Swift

    open func instantiateTaskStepNode(for step: RSDStep) -> RSDNodePathComponent?
  • Overridable factory method for returning a step controller for a given step.

    Declaration

    Swift

    open func loadStepController(for step: RSDStep) -> RSDStepController?
  • Return the path component for a previously visited node.

    Declaration

    Swift

    open func previousPathComponent(for step: RSDStep) -> (RSDNodePathComponent, RSDStepController?)?
  • Move back in the navigation to the current step on this path component.

    Declaration

    Swift

    open func moveBackToCurrentStep(from previousStep: RSDStep)
  • Move forward from this path subtask to the next step on the parent.

    Declaration

    Swift

    open func moveForwardToNextStep()
  • Move back from this path subtask to the previous step on the parent.

    Declaration

    Swift

    open func moveBackToPreviousStep()
  • Move to the first step in this task path in the given direction.

    Declaration

    Swift

    open func moveToFirstStep(from direction: RSDStepDirection)
  • Flag for tracking whether or not the task is loading from the taskInfo.

    Declaration

    Swift

    public private(set) var isLoading: Bool {
      get
      }
  • The repository to use to load a task.

    Declaration

    Swift

    lazy open var taskRepository: RSDTaskRepository { get set }
  • Fetch the task associated with this path. This method loads the task and sets up the task result once finished.

    Declaration

    Swift

    public func fetchTask()

    Parameters

    factory

    The factory to use to decode the task.

    completion

    The callback handler to call when the task is loaded.

  • Called when the task is successfully loaded.

    Declaration

    Swift

    open func handleTaskLoaded()
  • The data tracker (if any) for this task.

    Declaration

    Swift

    open var dataTracker: RSDTrackingTask? { get }
  • The previous data queried during task set up from the data manager.

    Declaration

    Swift

    public private(set) var previousTaskData: RSDTaskData? {
      get
      }
  • Called when the task is loaded and when thedataManager is set.

    Declaration

    Swift

    open func setupDataTracking()
  • Called when the task is finished and ready to move to the next subtask.

    Declaration

    Swift

    open func saveDataTracking()
  • Called when the task fails.

    Declaration

    Swift

    open func handleTaskFailure(with error: Error)
  • A listing of step results that were removed from the task result. These results can be accessed by a step view controller to load a result that was previously selected.

    Declaration

    Swift

    public private(set) var previousResults: [RSDResult]? {
      get
      }
  • Get the previous result for the given step.

    Declaration

    Swift

    open func previousResult(for step: RSDStep) -> RSDResult?
  • Append the previous result set with the given result.

    Declaration

    Swift

    open func append(previousResult: RSDResult)
  • Public method that the step controller can use to stop the async actions prior to moving away from the current step.

    Note

    If the step results will influence what step to move to next, then those results must be added to the step history before calling this method.

    Declaration

    Swift

    public final func stopAsyncActions(after step: RSDStep)

    Parameters

    step

    The current step.

  • Is this the last step in the task? By default, the conditions are met if the step is of type completion, the navigator does not indicate that there is another step after this one, and the skip action is undefined or does not navigate away from the step.

    Declaration

    Swift

    open func isTaskComplete(with step: RSDStep?) -> Bool

    Parameters

    step

    The step to test as the last step, or nil if the current step is the last.