RSDChoiceInputFieldObject
open class RSDChoiceInputFieldObject : RSDInputFieldObject, RSDChoiceInputField
RSDChoiceInputFieldObject is a concrete implementation of RSDChoiceInputField that subclasses RSDInputFieldObject
to include a list of choices for a multiple choice or single choice input field.
-
A list of choices for the input field.
Declaration
Swift
public let choices : [RSDChoice] -
Default initializer.
Declaration
Swift
public init(identifier: String, choices: [RSDChoice], dataType: RSDFormDataType, uiHint: RSDFormUIHint? = nil, prompt: String?)Parameters
identifierA short string that uniquely identifies the form item within the step.
choicesA list of choices for the input field.
dataTypeThe data type for this input field. The data type can have an associated ui hint.
uiHintA UI hint for how the study would prefer that the input field is displayed to the user.
promptA localized string that displays a short text offering a hint to the user of the data to be entered for this field.
-
Initialize from a
Decoder. This method uses theRSDFormDataType.BaseTypeassociated with this input field to decode a list ofRSDChoiceObjectobjects with the appropriateValuetype.example:
// A JSON example where this is for a single choice input field that is a `decimal` base type // with a survey rule where the task should exit if the matching answer is `0`. This will // decode the choices as an array of `RSDChoiceObject<Double>` objects. let json = """ { "identifier": "foo", "type": "form", "prompt": "Choose a number", "dataType": "singleChoice.decimal", "uiHint": "picker", "choices" : [{ "value" : 0, "text" : "0"}, { "value" : 1.2, "text" : "1.2"}, { "value" : 3.1425, "text" : "pi", "detail" : "Is the magic number" }, { "text" : "None of the above", "isExclusive" : true }], "matchingAnswer": 0 } """.data(using: .utf8)! // our data in native (JSON) format // A multiple choice question where the choices are coded as a list of text strings. This will // decode the choices as an array of `RSDChoiceObject<String>` objects where `value == text`. let json = """ { "identifier": "step3", "type": "form", "title": "Step 3", "dataType": "multipleChoice", "choices" : ["alpha", "beta", "charlie", "delta"] } """.data(using: .utf8)! // our data in native (JSON) format // A single choice question where each choice has an icon image representing the choice. This will // decode the choices as an array of `RSDChoiceObject<Int>` objects. let json = """ { "identifier": "happiness", "type": "form", "title": "How happy are you?", "dataType": "singleChoice.integer", "choices": [{ "text": "delighted", "detail": "Nothing could be better!", "value": 1, "icon": "moodScale1" }, { "text": "good", "detail": "Life is good.", "value": 2, "icon": "moodScale2" }, { "text": "so-so", "detail": "Things are okay, I guess.", "value": 3, "icon": "moodScale3" }, { "text": "sad", "detail": "I'm feeling a bit down.", "value": 4, "icon": "moodScale4" }, { "text": "miserable", "detail": "I cry into my pillow every night.", "value": 5, "icon": "moodScale5" }] } """.data(using: .utf8)! // our data in native (JSON) format // A JSON example where this is for a single choice input field that is a `bool` base type. This will // decode the choices as an array of `RSDChoiceObject<Bool>` objects. let json = """ { "identifier": "heightLimit", "type": "form", "prompt": "Are you tall?", "dataType": "singleChoice.boolean", "choices" : [{ "value" : true, "text" : "Yes"}, { "value" : false, "text" : "No"}, { "text" : "I don't know", "isExclusive" : true }], } """.data(using: .utf8)! // our data in native (JSON) formatThrows
DecodingErrorif there is a decoding error.Declaration
Swift
public required init(from decoder: Decoder) throwsParameters
decoderThe decoder to use to decode this instance.
-
Encode the result to the given encoder.
Throws
EncodingErrorDeclaration
Swift
override open func encode(to encoder: Encoder) throwsParameters
encoderThe encoder to use to encode this instance.
View on GitHub
RSDChoiceInputFieldObject Class Reference