RSDFactory

open class RSDFactory

RSDFactory handles customization of decoding the elements of a task. Applications should override this factory to add custom elements required to run their task modules.

  • Singleton for the shared factory. If a factory is not passed in when creating tasks then this will be used.

    Declaration

    Swift

    public static var shared = RSDFactory()
  • The type of device to point use when decoding different text depending upon the target device.

    Declaration

    Swift

    public internal(set) var deviceType: RSDDeviceType =
  • Undocumented

    Declaration

    Swift

    public init()
  • Optional data source for this factory.

    Declaration

    Swift

    public var taskDataSource: RSDTaskDataSource?
  • Get a string that will identify the type of object to instantiate for the given decoder.

    By default, this will look in the container for the decoder for a key/value pair where the key == type and the value is a String.

    Throws

    DecodingError if the type name cannot be decoded.

    Declaration

    Swift

    open func typeName(from decoder:Decoder) throws -> String?

    Parameters

    decoder

    The decoder to inspect.

    Return Value

    The string representing this class type (if found).

  • Use the resource transformer to get a data object to decode into a task.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeTask(with resourceTransformer: RSDResourceTransformer, taskInfo: RSDTaskInfoStep? = nil, schemaInfo: RSDSchemaInfo? = nil) throws -> RSDTask

    Parameters

    resourceTransformer

    The resource transformer.

    Return Value

    The decoded task.

  • Decode an object with top-level data (json or plist) for a given resourceType, typeName, and taskInfo.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeTask(with data: Data, resourceType: RSDResourceType, typeName: String? = nil, taskInfo: RSDTaskInfoStep? = nil, schemaInfo: RSDSchemaInfo? = nil) throws -> RSDTask

    Parameters

    data

    The data to use to decode the object.

    resourceType

    The type of resource (json or plist).

    typeName

    The class name type key for this task (if any).

    taskInfo

    The task info used to create this task (if any).

    Return Value

    The decoded task.

  • Decode the task info from this decoder. This method must return a task info object. The default implementation will return a RSDTaskInfoStepObject.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeTaskInfo(from decoder: Decoder) throws -> RSDTaskInfoStep

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The task info created from this decoder.

  • Decode the schema info from this decoder. This method must return a schema info object. The default implementation will return a RSDSchemaInfoObject.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeSchemaInfo(from decoder: Decoder) throws -> RSDSchemaInfo

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The schema info created from this decoder.

  • Encode the schema info from the given task result to the given encoder. This allows a subclass of the factory to encode additional schema information to the schema info defined by the RSDSchemaInfo protocol.

    Declaration

    Swift

    open func encodeSchemaInfo(from taskResult: RSDTaskResult, to encoder: Encoder) throws

    Parameters

    taskResult

    The task result being encoded.

    encoder

    The nested encoder to encode the schema info to.

  • Decode the task transformer from this decoder. This method must return a task transformer object. The default implementation will return a RSDResourceTransformerObject.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeTaskTransformer(from decoder: Decoder) throws -> RSDTaskTransformer

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The object created from this decoder.

  • Decode the section step transformer from this decoder. This method must return a section step transformer object. The default implementation will return a RSDResourceTransformerObject.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeSectionStepTransformer(from decoder: Decoder) throws -> RSDSectionStepTransformer

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The object created from this decoder.

  • Decode the step navigator from this decoder. This method must return a step navigator. The default implementation will return a RSDConditionalStepNavigatorObject.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeStepNavigator(from decoder: Decoder) throws -> RSDStepNavigator

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The step navigator created from this decoder.

  • Convenience method for decoding a list of steps.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    public func decodeSteps(from container: UnkeyedDecodingContainer) throws -> [RSDStep]

    Parameters

    container

    The unkeyed container with the steps.

    Return Value

    An array of the steps.

  • Decode the step from this decoder.

    This method can be overridden to return nil if the step should be skipped. For example, if the step does not apply for a task run on an Apple watch or iPad, but does apply to a task run on an iPhone.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeStep(from decoder: Decoder) throws -> RSDStep?

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The step (if any) created from this decoder.

  • Decode the step from this decoder. This method can be overridden to return nil if the step should be skipped.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeStep(from decoder:Decoder, with type:RSDStepType) throws -> RSDStep?

    Parameters

    type

    The StepType to instantiate.

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The step (if any) created from this decoder.

  • Decode the step into a transfrom step. By default, this will create a RSDTransformerStepObject.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func transformStep(from decoder: Decoder) throws -> RSDTransformerStep

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The step transform created from this decoder.

  • Decode the transformable step. By default, this will create a RSDSectionStepObject.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeTransformableStep(from decoder: Decoder) throws -> RSDStep

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The section step created from transforming this decoder.

  • Decode the input field from this decoder. This method can be overridden to return nil if the input field should be skipped.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeInputField(from decoder: Decoder) throws -> RSDInputField?

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The step (if any) created from this decoder.

  • Decode the input field from this decoder. This method can be overridden to return nil if the input field should be skipped.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeInputField(from decoder:Decoder, with dataType: RSDFormDataType) throws -> RSDInputField?

    Parameters

    dataType

    The data type for this step.

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The input field (if any) created from this decoder.

  • Decode the text validator from this decoder. The default implementation will instantiate a RSDRegExValidatorObject from the decoder.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeTextValidator(from decoder: Decoder) throws -> RSDTextValidator?

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The text validator created from this decoder.

  • Decode a number formatter from this decoder. The default implementation will instantiate a NumberFormatter from the decoder using the convenience method defined in an extension in this framework.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeNumberFormatter(from decoder: Decoder) throws -> NumberFormatter

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The number formatter created from this decoder.

  • Decode a conditional rule from the given decoder. This method can be overridden to return nil if the conditional rule should be ignored for this platform.

    Note

    The base factory does not currently support any conditional rule objects. The conditional rule is included here for future implementation of data tracking across runs of a task. (syoung 10/03/2017)

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeConditionalRule(from decoder:Decoder) throws -> RSDConditionalRule?

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The conditional rule (if any) created from this decoder.

  • Decode a conditional rule from the given decoder. This method can be overridden to return nil if the conditional rule should be ignored for this platform.

    Note

    The base factory does not currently support any conditional rule objects. The conditional rule is included here for future implementation of data tracking.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeConditionalRule(from decoder:Decoder, with typeName: String) throws -> RSDConditionalRule?

    Parameters

    typeName

    The string representing the class name for this conditional rule.

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The conditional rule (if any) created from this decoder.

  • Decode an ui action from the given decoder.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeUIAction(from decoder:Decoder, for actionType: RSDUIActionType) throws -> RSDUIAction

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The UI action created from this decoder.

  • Decode an async action configuration from the given decoder. This method can be overridden to return nil if the action should be ignored for this platform.

    Note

    The base factory does not currently support any async action objects. The factory method is included here for subclassing purposes. (syoung 10/03/2017)

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeAsyncActionConfiguration(from decoder:Decoder) throws -> RSDAsyncActionConfiguration?

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The configuration (if any) created from this decoder.

  • Decode an async action configuration from the given decoder. This method can be overridden to return nil if the action should be ignored for this platform.

    Note

    The base factory does not currently support any async action objects. The factory method is included here for subclassing purposes. (syoung 10/03/2017)

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeAsyncActionConfiguration(from decoder:Decoder, with typeName: String) throws -> RSDAsyncActionConfiguration?

    Parameters

    typeName

    The string representing the class name for this conditional rule.

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The configuration (if any) created from this decoder.

  • Convenience method for decoding a list of results.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    public func decodeResults(from container: UnkeyedDecodingContainer) throws -> [RSDResult]

    Parameters

    container

    The unkeyed container with the results.

    Return Value

    An array of the results.

  • Decode the result from this decoder.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeResult(from decoder: Decoder) throws -> RSDResult

    Parameters

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The result (if any) created from this decoder.

  • Decode the result from this decoder.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func decodeResult(from decoder: Decoder, with resultType: RSDResultType) throws -> RSDResult

    Parameters

    typeName

    The string representing the class name for this object.

    decoder

    The decoder to use to instatiate the object.

    Return Value

    The result (if any) created from this decoder.

  • Get the date result formatter to use for the given calendar components.

    Returned Formatter Description
    dateOnlyFormatter If only date components (year, month, day) are included.
    timeOnlyFormatter If only time components (hour, minute, second) are included.
    timestampFormatter If both date and time components are included.

    Declaration

    Swift

    open func dateResultFormatter(from calendarComponents: Set<Calendar.Component>) -> DateFormatter

    Parameters

    calendarComponents

    The calendar components to include.

    Return Value

    The appropriate date formatter.

  • DateFormatter to use for coding date-only strings. Default = rsd_ISO8601DateOnlyFormatter.

    Declaration

    Swift

    open var dateOnlyFormatter: DateFormatter
  • DateFormatter to use for coding time-only strings. Default = rsd_ISO8601TimeOnlyFormatter.

    Declaration

    Swift

    open var timeOnlyFormatter: DateFormatter
  • DateFormatter to use for coding timestamp strings that include both date and time components. Default = rsd_ISO8601TimestampFormatter.

    Declaration

    Swift

    open var timestampFormatter: DateFormatter
  • Create a JSONDecoder with this factory assigned in the user info keys as the factory to use when decoding this object.

    Declaration

    Swift

    open func createJSONDecoder() -> JSONDecoder
  • Create a PropertyListDecoder with this factory assigned in the user info keys as the factory to use when decoding this object.

    Declaration

    Swift

    open func createPropertyListDecoder() -> PropertyListDecoder
  • Create the appropriate decoder for the given resource type. This method will return an encoder that conforms to the RSDFactoryDecoder protocol. The decoder will assign the user info coding keys as appropriate.

    Throws

    DecodingError if the object cannot be decoded.

    Declaration

    Swift

    open func createDecoder(for resourceType: RSDResourceType, taskInfo: RSDTaskInfoStep? = nil, schemaInfo: RSDSchemaInfo? = nil) throws -> RSDFactoryDecoder

    Parameters

    resourceType

    The resource type.

    taskInfo

    The task info to pass with the decoder.

    schemaInfo

    The schema info to pass with the decoder.

    Return Value

    The decoder for the given type.

  • Decode a date from a string. This method is used during object decoding and is defined as open so that subclass factories can define their own formatters.

    Declaration

    Swift

    open func decodeDate(from string: String, formatter: DateFormatter? = nil) -> Date?

    Parameters

    string

    The string to use in decoding the date.

    formatter

    A formatter to use. If provided, this formatter will be used. If nil, then the string will be inspected to see if it matches any of the expected formats for date and time, time only, or date only.

    Return Value

    The date created from this string.

  • Create a JSONEncoder with this factory assigned in the user info keys as the factory to use when encoding objects.

    Declaration

    Swift

    open func createJSONEncoder() -> JSONEncoder
  • Create a PropertyListEncoder with this factory assigned in the user info keys as the factory to use when encoding objects.

    Declaration

    Swift

    open func createPropertyListEncoder() -> PropertyListEncoder
  • Overridable method for encoding a date to a string. By default, this method uses the timestampFormatter as the date formatter.

    Declaration

    Swift

    open func encodeString(from date: Date, codingPath: [CodingKey]) -> String