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 aString.Throws
DecodingErrorif the type name cannot be decoded.Declaration
Swift
open func typeName(from decoder:Decoder) throws -> String?Parameters
decoderThe 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeTask(with resourceTransformer: RSDResourceTransformer, taskInfo: RSDTaskInfoStep? = nil, schemaInfo: RSDSchemaInfo? = nil) throws -> RSDTaskParameters
resourceTransformerThe resource transformer.
Return Value
The decoded task.
-
Decode an object with top-level data (json or plist) for a given
resourceType,typeName, andtaskInfo.Throws
DecodingErrorif 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 -> RSDTaskParameters
dataThe data to use to decode the object.
resourceTypeThe type of resource (json or plist).
typeNameThe class name type key for this task (if any).
taskInfoThe 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeTaskInfo(from decoder: Decoder) throws -> RSDTaskInfoStepParameters
decoderThe 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeSchemaInfo(from decoder: Decoder) throws -> RSDSchemaInfoParameters
decoderThe 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
RSDSchemaInfoprotocol.Declaration
Swift
open func encodeSchemaInfo(from taskResult: RSDTaskResult, to encoder: Encoder) throwsParameters
taskResultThe task result being encoded.
encoderThe 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeTaskTransformer(from decoder: Decoder) throws -> RSDTaskTransformerParameters
decoderThe 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeSectionStepTransformer(from decoder: Decoder) throws -> RSDSectionStepTransformerParameters
decoderThe 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeStepNavigator(from decoder: Decoder) throws -> RSDStepNavigatorParameters
decoderThe 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
public func decodeSteps(from container: UnkeyedDecodingContainer) throws -> [RSDStep]Parameters
containerThe 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
nilif 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeStep(from decoder: Decoder) throws -> RSDStep?Parameters
decoderThe 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
nilif the step should be skipped.Throws
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeStep(from decoder:Decoder, with type:RSDStepType) throws -> RSDStep?Parameters
typeThe
StepTypeto instantiate.decoderThe 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func transformStep(from decoder: Decoder) throws -> RSDTransformerStepParameters
decoderThe 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeTransformableStep(from decoder: Decoder) throws -> RSDStepParameters
decoderThe 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
nilif the input field should be skipped.Throws
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeInputField(from decoder: Decoder) throws -> RSDInputField?Parameters
decoderThe 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
nilif the input field should be skipped.Throws
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeInputField(from decoder:Decoder, with dataType: RSDFormDataType) throws -> RSDInputField?Parameters
dataTypeThe data type for this step.
decoderThe 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
RSDRegExValidatorObjectfrom the decoder.Throws
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeTextValidator(from decoder: Decoder) throws -> RSDTextValidator?Parameters
decoderThe 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
NumberFormatterfrom the decoder using the convenience method defined in an extension in this framework.Throws
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeNumberFormatter(from decoder: Decoder) throws -> NumberFormatterParameters
decoderThe 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
nilif 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeConditionalRule(from decoder:Decoder) throws -> RSDConditionalRule?Parameters
decoderThe 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
nilif 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeConditionalRule(from decoder:Decoder, with typeName: String) throws -> RSDConditionalRule?Parameters
typeNameThe string representing the class name for this conditional rule.
decoderThe 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeUIAction(from decoder:Decoder, for actionType: RSDUIActionType) throws -> RSDUIActionParameters
decoderThe 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
nilif 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeAsyncActionConfiguration(from decoder:Decoder) throws -> RSDAsyncActionConfiguration?Parameters
decoderThe 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
nilif 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeAsyncActionConfiguration(from decoder:Decoder, with typeName: String) throws -> RSDAsyncActionConfiguration?Parameters
typeNameThe string representing the class name for this conditional rule.
decoderThe 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
DecodingErrorif the object cannot be decoded.Declaration
Swift
public func decodeResults(from container: UnkeyedDecodingContainer) throws -> [RSDResult]Parameters
containerThe unkeyed container with the results.
Return Value
An array of the results.
-
Decode the result from this decoder.
Throws
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeResult(from decoder: Decoder) throws -> RSDResultParameters
decoderThe decoder to use to instatiate the object.
Return Value
The result (if any) created from this decoder.
-
Decode the result from this decoder.
Throws
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeResult(from decoder: Decoder, with resultType: RSDResultType) throws -> RSDResultParameters
typeNameThe string representing the class name for this object.
decoderThe 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 dateOnlyFormatterIf only date components (year, month, day) are included. timeOnlyFormatterIf only time components (hour, minute, second) are included. timestampFormatterIf both date and time components are included. Declaration
Swift
open func dateResultFormatter(from calendarComponents: Set<Calendar.Component>) -> DateFormatterParameters
calendarComponentsThe calendar components to include.
Return Value
The appropriate date formatter.
-
DateFormatterto use for coding date-only strings. Default =rsd_ISO8601DateOnlyFormatter.Declaration
Swift
open var dateOnlyFormatter: DateFormatter -
DateFormatterto use for coding time-only strings. Default =rsd_ISO8601TimeOnlyFormatter.Declaration
Swift
open var timeOnlyFormatter: DateFormatter -
DateFormatterto use for coding timestamp strings that include both date and time components. Default =rsd_ISO8601TimestampFormatter.Declaration
Swift
open var timestampFormatter: DateFormatter
-
Create a
JSONDecoderwith 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
PropertyListDecoderwith 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
RSDFactoryDecoderprotocol. The decoder will assign the user info coding keys as appropriate.Throws
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func createDecoder(for resourceType: RSDResourceType, taskInfo: RSDTaskInfoStep? = nil, schemaInfo: RSDSchemaInfo? = nil) throws -> RSDFactoryDecoderParameters
resourceTypeThe resource type.
taskInfoThe task info to pass with the decoder.
schemaInfoThe 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
openso that subclass factories can define their own formatters.Declaration
Swift
open func decodeDate(from string: String, formatter: DateFormatter? = nil) -> Date?Parameters
stringThe string to use in decoding the date.
formatterA 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
JSONEncoderwith this factory assigned in the user info keys as the factory to use when encoding objects.Declaration
Swift
open func createJSONEncoder() -> JSONEncoder -
Create a
PropertyListEncoderwith 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
timestampFormatteras the date formatter.Declaration
Swift
open func encodeString(from date: Date, codingPath: [CodingKey]) -> String
View on GitHub
RSDFactory Class Reference