RSDFormStepDataSource
public protocol RSDFormStepDataSource : class
RSDFormStepDataSource
: the internal model for a table view controller. It provides the UITableViewDataSource,
manages and stores answers provided thru user input, and provides an RSDResult with those answers upon request.
It also provides several convenience methods for saving or selecting answers, checking if all answers are valid, and retrieving specific model objects that may be needed by the ViewController.
The tableView data source is comprised of 3 objects:
RSDTableSection
: An object representing a section in the tableView. It has one or more RSDTableItemGroup objects.RSDTableItemGroup
: An object representing a specific question supplied byRSDStep
as an input field. Upon init(), the ItemGroup will create one or moreRSDTableItem
objects representing the answer options for theRSDInputField
. The ItemGroup is responsible for storing/computing the answers for itsRSDInputField
.RSDTableItem
: An object representing a specific answer option from the ItemGroup (RSDInputField), such as a Yes or No choice in a boolean question or a string or number that’s entered thru a text field. There will be one TableItem for each indexPath in the tableView.
-
The delegate associated with this data source.
Declaration
Swift
weak var delegate: RSDFormStepDataSourceDelegate?
-
The step associated with this data source.
Declaration
Swift
var step: RSDStep
-
The UI hints supported by this data source.
Declaration
Swift
var supportedHints: Set<RSDFormUIHint>
-
The current task path.
Declaration
Swift
var taskPath: RSDTaskPath
-
The table sections for this data source.
Declaration
Swift
var sections: [RSDTableSection]
-
This method is used to create an appropriate answer result for a given item group.
Declaration
Swift
func instantiateAnswerResult(for itemGroup: RSDInputFieldTableItemGroup) -> RSDAnswerResult?
Parameters
itemGroup
The item group.
Return Value
The instantiated answer result (if applicable)
-
This method is used to vend the appropriate step answer result collection.
Declaration
Swift
func collectionResult() -> RSDCollectionResult
Return Value
The associated collection result.
-
itemGroup(with:)
Extension methodRetrieve the
RSDTableItemGroup
with a specificRSDInputField
identifier.Declaration
Swift
public func itemGroup(with identifier: String) -> RSDTableItemGroup?
Parameters
identifier
The identifier of the
RSDInputField
assigned to the item group.Return Value
The requested
RSDTableItemGroup
, or nil if it cannot be found. -
itemGroup(at:)
Extension methodRetrieve the ‘RSDTableItemGroup’ for a specific IndexPath.
Declaration
Swift
public func itemGroup(at indexPath: IndexPath) -> RSDTableItemGroup?
Parameters
indexPath
The index path that represents the item group in the table view.
Return Value
The requested
RSDTableItemGroup
, or nil if it cannot be found. -
nextItem(after:)
Extension methodRetrieve the next item group after the current one at the given index path.
Declaration
Swift
public func nextItem(after indexPath: IndexPath) -> RSDTableItemGroup?
Parameters
indexPath
The index path that represents the item group in the table view.
Return Value
The next
RSDTableItemGroup
ornil
if this was the last item. -
indexPath(for:)
Extension methodRetrieve the index path that points at the given item group.
Declaration
Swift
public func indexPath(for itemGroup: RSDTableItemGroup) -> IndexPath?
Parameters
itemGroup
The item group.
Return Value
The index path for the given item group or
nil
if not found. -
saveAnswer(_:at:)
Extension methodSave an answer for a specific IndexPath.
Throws
RSDInputFieldError
if the answer is invalid.Declaration
Swift
public func saveAnswer(_ answer: Any, at indexPath: IndexPath) throws
Parameters
answer
The object to be save as the answer.
indexPath
The
IndexPath
that represents theRSDTableItem
in the table view. -
selectAnswer(item:at:)
Extension methodSelect or deselect the answer option for a specific IndexPath.
Throws
RSDInputFieldError
if the selection is invalid.Declaration
Swift
public func selectAnswer(item: RSDChoiceTableItem, at indexPath: IndexPath) throws
Parameters
indexPath
The
IndexPath
that represents theRSDTableItem
in the table view. -
allAnswersValid()
Extension methodDetermine if all answers are valid. Also checks the case where answers are required but one has not been provided.
Declaration
Swift
public func allAnswersValid() -> Bool
Return Value
A
Bool
indicating if all answers are valid. -
tableItem(at:)
Extension methodRetrieve the
RSDTableItem
for a specificIndexPath
.Declaration
Swift
public func tableItem(at indexPath: IndexPath) -> RSDTableItem?
Parameters
indexPath
The
IndexPath
that represents the table item in the table view.Return Value
The requested
RSDTableItem
, or nil if it cannot be found.