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 { get } -
Optional shared tracking rules
Declaration
Swift
open var trackingRules: [RSDTrackingRule]
-
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.Seealso
RSDTaskResourceTransformerDeclaration
Swift
open func decodeTask(with resourceTransformer: RSDResourceTransformer, taskIdentifier: String? = nil, schemaInfo: RSDSchemaInfo? = nil) throws -> RSDTaskParameters
resourceTransformerThe resource transformer.
taskIdentifierThe identifier of the task.
schemaInfoThe schema info for the task.
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.Seealso
RSDTaskResourceTransformerDeclaration
Swift
open func decodeTask(with data: Data, resourceType: RSDResourceType, typeName: String? = nil, taskIdentifier: String? = nil, schemaInfo: RSDSchemaInfo? = nil, bundle: Bundle? = 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).
taskIdentifierThe identifier of the task.
schemaInfoThe schema info for the task.
Return Value
The decoded task.
-
Decode a task from the decoder.
Throws
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeTask(with data: Data, from decoder: RSDFactoryDecoder) throws -> RSDTaskParameters
dataThe data to use to decode the object.
decoderThe decoder to use to instantiate the object.
Return Value
The decoded task.
-
Decode a task from the decoder.
Throws
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeTask(from decoder: Decoder) throws -> RSDTaskParameters
decoderThe decoder to use to instantiate the object.
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.Seealso
RSDTaskGroupObjectDeclaration
Swift
open func decodeTaskInfo(from decoder: Decoder) throws -> RSDTaskInfoParameters
decoderThe decoder to use to instantiate 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.Seealso
RSDTaskResultObjectDeclaration
Swift
open func decodeSchemaInfo(from decoder: Decoder) throws -> RSDSchemaInfoParameters
decoderThe decoder to use to instantiate 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 instantiate 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
RSDConditionalStepNavigatorObjectif the type is not in the decoder.Throws
DecodingErrorif the object cannot be decoded.Seealso
RSDTaskObjectDeclaration
Swift
open func decodeStepNavigator(from decoder: Decoder) throws -> RSDStepNavigatorParameters
decoderThe decoder to use to instantiate the object.
Return Value
The step navigator created from this decoder.
-
Decode the step navigator from this decoder. This method must return a step navigator. The default implementation will return a
RSDConditionalStepNavigatorObjectfor an unrecognized type.Throws
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeStepNavigator(from decoder: Decoder, with type: RSDStepNavigatorType) throws -> RSDStepNavigatorParameters
decoderThe decoder to use to instantiate the object.
typeThe
RSDStepNavigatorTypeto instantiate.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 instantiate 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 instantiate 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
RSDStepTransformerObject.Throws
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeStepTransformer(from decoder: Decoder) throws -> RSDStepTransformerParameters
decoderThe decoder to use to instantiate the object.
Return Value
The step transform created from this decoder.
-
Decode the transformable step. By default, this will return the
transformedStepfrom aRSDStepTransformer.Throws
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeTransformableStep(from decoder: Decoder) throws -> RSDStepParameters
decoderThe decoder to use to instantiate the object.
Return Value
The 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.Seealso
RSDFormUIStepObjectDeclaration
Swift
open func decodeInputField(from decoder: Decoder) throws -> RSDInputField?Parameters
decoderThe decoder to use to instantiate 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
decoderThe decoder to use to instantiate the object.
dataTypeThe type for this input field.
Return Value
The input field (if any) created from this decoder.
-
Overridable function for decoding a list of survey rules from an unkeyed container for a given data type. The default implementation will instantiate a list of
RSDComparableSurveyRuleObjectinstances appropriate to theBaseTypeof the given data type.- example:
The following will decode the
surveyRules
key as an array of[RSDComparableSurveyRuleObject<Int>].```` { "identifier": "foo", "type": "integer", "surveyRules" : [ { "skipToIdentifier": "lessThan", "ruleOperator": "lt", "matchingAnswer": 0 }, { "skipToIdentifier": "greaterThan", "ruleOperator": "gt", "matchingAnswer": 1 } ] } ````Throws
DecodingErrorSeealso
RSDInputFieldObjectDeclaration
Swift
open func decodeSurveyRules(from rulesContainer: UnkeyedDecodingContainer, for dataType: RSDFormDataType) throws -> [RSDSurveyRule]Parameters
rulesContainerThe unkeyed container for the survey rules.
dataTypeThe data type associated with this instance.
Return Value
An array of survey rules.
-
Overridable factory method for returning a survey rule. By default, this will return a
RSDComparableSurveyRuleObjectappropriate to the base type of the data type.Declaration
Swift
open func decodeSurveyRule(from decoder: Decoder, for dataType: RSDFormDataType) throws -> RSDSurveyRule
-
Overridable function for decoding the range from the decoder. The default implementation will decode a range object appropriate to the data type.
RSDFormDataType.BaseType Type of range to decode .integer, .decimal, .fraction RSDNumberRangeObject.date RSDDateRangeObject.year RSDDateRangeObjectorRSDNumberRangeObject.duration RSDDurationRangeObjectThrows
DecodingErrorSeealso
RSDInputFieldObjectDeclaration
Swift
open func decodeRange(from decoder: Decoder, for dataType: RSDFormDataType) throws -> RSDRange?Parameters
decoderThe decoder used to decode this object.
dataTypeThe data type associated with this instance.
Return Value
An appropriate instance of
RSDRange.
-
Decode the text validator from this decoder. The default implementation will instantiate a
RSDRegExValidatorObjectfrom the decoder.Throws
DecodingErrorif the object cannot be decoded.Seealso
RSDTextFieldOptionsObjectDeclaration
Swift
open func decodeTextValidator(from decoder: Decoder) throws -> RSDTextValidator?Parameters
decoderThe decoder to use to instantiate 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.Seealso
RSDNumberRangeObjectDeclaration
Swift
open func decodeNumberFormatter(from decoder: Decoder) throws -> NumberFormatterParameters
decoderThe decoder to use to instantiate the object.
Return Value
The number formatter created from this decoder.
-
Decode UI action from the given decoder.
Throws
DecodingErrorif the object cannot be decoded.Seealso
RSDUIActionHandlerObjectDeclaration
Swift
open func decodeUIAction(from decoder: Decoder, for actionType: RSDUIActionType) throws -> RSDUIActionParameters
decoderThe decoder to use to instantiate the object.
actionTypeThe action type for this button.
objectTypeThe object type to which this action should be cast.
Return Value
The UI action created from this decoder.
-
Decode UI action from the given decoder.
Throws
DecodingErrorif the object cannot be decoded.Declaration
Swift
open func decodeUIAction(from decoder: Decoder, with objectType: RSDUIActionObjectType) throws -> RSDUIActionParameters
decoderThe decoder to use to instantiate the object.
objectTypeThe object type to which this action should be cast.
Return Value
The UI action created from this decoder.
-
Decode UI color mapping theme from the given decoder.
Throws
DecodingErrorif the object cannot be decoded.Seealso
RSDUIStepObjectDeclaration
Swift
open func decodeColorMappingThemeElement(from decoder: Decoder) throws -> RSDColorMappingThemeElement?Parameters
decoderThe decoder to use to instantiate the object.
Return Value
The UI color theme created from this decoder.
-
Decode UI view theme from the given decoder.
Throws
DecodingErrorif the object cannot be decoded.Seealso
RSDUIStepObjectDeclaration
Swift
open func decodeViewThemeElement(from decoder: Decoder) throws -> RSDViewThemeElement?Parameters
decoderThe decoder to use to instantiate the object.
Return Value
The UI view theme created from this decoder.
-
Decode UI image theme from the given decoder.
Throws
DecodingErrorif the object cannot be decoded.Seealso
RSDUIStepObjectDeclaration
Swift
open func decodeImageThemeElement(from decoder: Decoder) throws -> RSDImageThemeElement?Parameters
decoderThe decoder to use to instantiate the object.
Return Value
The UI image theme 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.Seealso
Declaration
Swift
open func decodeAsyncActionConfiguration(from decoder: Decoder) throws -> RSDAsyncActionConfiguration?Parameters
decoderThe decoder to use to instantiate 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 instantiate 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 instantiate 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
resultTypeThe result type for this result.
decoderThe decoder to use to instantiate 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 { get } -
DateFormatterto use for coding time-only strings. Default =rsd_ISO8601TimeOnlyFormatter.Declaration
Swift
open var timeOnlyFormatter: DateFormatter { get } -
DateFormatterto use for coding timestamp strings that include both date and time components. Default =rsd_ISO8601TimestampFormatter.Declaration
Swift
open var timestampFormatter: DateFormatter { get } -
The default coding strategy to use for non-conforming elements.
Declaration
Swift
open var nonConformingCodingStrategy: (positiveInfinity: String, negativeInfinity: String, nan: String)
-
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(bundle: Bundle? = nil) -> 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(bundle: Bundle? = nil) -> 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, taskIdentifier: String? = nil, schemaInfo: RSDSchemaInfo? = nil, bundle: Bundle? = nil) throws -> RSDFactoryDecoderParameters
resourceTypeThe resource type.
taskIdentifierThe task identifier 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 -
Overridable method for encoding data to a string. By default, this method uses base64 encoding.
Declaration
Swift
open func encodeString(from data: Data, codingPath: [CodingKey]) -> String
View on GitHub
RSDFactory Class Reference