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
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.Seealso
RSDTaskResourceTransformer
Declaration
Swift
open func decodeTask(with resourceTransformer: RSDResourceTransformer, taskIdentifier: String? = nil, schemaInfo: RSDSchemaInfo? = nil) throws -> RSDTask
Parameters
resourceTransformer
The resource transformer.
taskIdentifier
The identifier of the task.
schemaInfo
The 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
DecodingError
if the object cannot be decoded.Seealso
RSDTaskResourceTransformer
Declaration
Swift
open func decodeTask(with data: Data, resourceType: RSDResourceType, typeName: String? = nil, taskIdentifier: String? = nil, schemaInfo: RSDSchemaInfo? = nil, bundle: Bundle? = 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).
taskIdentifier
The identifier of the task.
schemaInfo
The schema info for the task.
Return Value
The decoded task.
-
Decode a task from the decoder.
Throws
DecodingError
if the object cannot be decoded.Declaration
Swift
open func decodeTask(with data: Data, from decoder: RSDFactoryDecoder) throws -> RSDTask
Parameters
data
The data to use to decode the object.
decoder
The decoder to use to instantiate the object.
Return Value
The decoded task.
-
Decode a task from the decoder.
Throws
DecodingError
if the object cannot be decoded.Declaration
Swift
open func decodeTask(from decoder: Decoder) throws -> RSDTask
Parameters
decoder
The 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
DecodingError
if the object cannot be decoded.Seealso
RSDTaskGroupObject
Declaration
Swift
open func decodeTaskInfo(from decoder: Decoder) throws -> RSDTaskInfo
Parameters
decoder
The 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
DecodingError
if the object cannot be decoded.Seealso
RSDTaskResultObject
Declaration
Swift
open func decodeSchemaInfo(from decoder: Decoder) throws -> RSDSchemaInfo
Parameters
decoder
The 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
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 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
RSDConditionalStepNavigatorObject
if the type is not in the decoder.Throws
DecodingError
if the object cannot be decoded.Seealso
RSDTaskObject
Declaration
Swift
open func decodeStepNavigator(from decoder: Decoder) throws -> RSDStepNavigator
Parameters
decoder
The 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
RSDConditionalStepNavigatorObject
for an unrecognized type.Throws
DecodingError
if the object cannot be decoded.Declaration
Swift
open func decodeStepNavigator(from decoder: Decoder, with type: RSDStepNavigatorType) throws -> RSDStepNavigator
Parameters
decoder
The decoder to use to instantiate the object.
type
The
RSDStepNavigatorType
to instantiate.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 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
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 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
DecodingError
if the object cannot be decoded.Declaration
Swift
open func decodeStepTransformer(from decoder: Decoder) throws -> RSDStepTransformer
Parameters
decoder
The 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
transformedStep
from aRSDStepTransformer
.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 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
nil
if the input field should be skipped.Throws
DecodingError
if the object cannot be decoded.Seealso
RSDFormUIStepObject
Declaration
Swift
open func decodeInputField(from decoder: Decoder) throws -> RSDInputField?
Parameters
decoder
The 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
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
decoder
The decoder to use to instantiate the object.
dataType
The 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
RSDComparableSurveyRuleObject
instances appropriate to theBaseType
of 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
DecodingError
Seealso
RSDInputFieldObject
Declaration
Swift
open func decodeSurveyRules(from rulesContainer: UnkeyedDecodingContainer, for dataType: RSDFormDataType) throws -> [RSDSurveyRule]
Parameters
rulesContainer
The unkeyed container for the survey rules.
dataType
The 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
RSDComparableSurveyRuleObject
appropriate 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 RSDDateRangeObject
orRSDNumberRangeObject
.duration RSDDurationRangeObject
Throws
DecodingError
Seealso
RSDInputFieldObject
Declaration
Swift
open func decodeRange(from decoder: Decoder, for dataType: RSDFormDataType) throws -> RSDRange?
Parameters
decoder
The decoder used to decode this object.
dataType
The 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
RSDRegExValidatorObject
from the decoder.Throws
DecodingError
if the object cannot be decoded.Seealso
RSDTextFieldOptionsObject
Declaration
Swift
open func decodeTextValidator(from decoder: Decoder) throws -> RSDTextValidator?
Parameters
decoder
The 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
NumberFormatter
from the decoder using the convenience method defined in an extension in this framework.Throws
DecodingError
if the object cannot be decoded.Seealso
RSDNumberRangeObject
Declaration
Swift
open func decodeNumberFormatter(from decoder: Decoder) throws -> NumberFormatter
Parameters
decoder
The decoder to use to instantiate the object.
Return Value
The number formatter created from this decoder.
-
Decode UI action from the given decoder.
Throws
DecodingError
if the object cannot be decoded.Seealso
RSDUIActionHandlerObject
Declaration
Swift
open func decodeUIAction(from decoder: Decoder, for actionType: RSDUIActionType) throws -> RSDUIAction
Parameters
decoder
The decoder to use to instantiate the object.
actionType
The action type for this button.
objectType
The 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
DecodingError
if the object cannot be decoded.Declaration
Swift
open func decodeUIAction(from decoder: Decoder, with objectType: RSDUIActionObjectType) throws -> RSDUIAction
Parameters
decoder
The decoder to use to instantiate the object.
objectType
The 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
DecodingError
if the object cannot be decoded.Seealso
RSDUIStepObject
Declaration
Swift
open func decodeColorMappingThemeElement(from decoder: Decoder) throws -> RSDColorMappingThemeElement?
Parameters
decoder
The 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
DecodingError
if the object cannot be decoded.Seealso
RSDUIStepObject
Declaration
Swift
open func decodeViewThemeElement(from decoder: Decoder) throws -> RSDViewThemeElement?
Parameters
decoder
The 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
DecodingError
if the object cannot be decoded.Seealso
RSDUIStepObject
Declaration
Swift
open func decodeImageThemeElement(from decoder: Decoder) throws -> RSDImageThemeElement?
Parameters
decoder
The 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
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.Seealso
Declaration
Swift
open func decodeAsyncActionConfiguration(from decoder: Decoder) throws -> RSDAsyncActionConfiguration?
Parameters
decoder
The 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
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 instantiate 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 instantiate 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
resultType
The result type for this result.
decoder
The 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 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 { get }
-
DateFormatter
to use for coding time-only strings. Default =rsd_ISO8601TimeOnlyFormatter
.Declaration
Swift
open var timeOnlyFormatter: DateFormatter { get }
-
DateFormatter
to 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
JSONDecoder
with 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
PropertyListDecoder
with 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
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, taskIdentifier: String? = nil, schemaInfo: RSDSchemaInfo? = nil, bundle: Bundle? = nil) throws -> RSDFactoryDecoder
Parameters
resourceType
The resource type.
taskIdentifier
The task identifier 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
-
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