Elements Common API
Votable polls are subclasses of BasePoll class. This class should be used in code for generalization.
public class BasePoll: Frame
BasePoll encapsulates element state, voting logic contains code for State of the parent class. state manipulation, results, and notify subscribers about changes…
Elements which can be revealed are derived from RevelablePoll class.
public class RevelablePoll: BasePoll
RevelablePoll class contains methods for accessing Revealed state, if a poll has it.
Returns element id.
id: String
Returns element type.
type: String
Returns element content type.
contentType: String
Returns element custom fields as JSON.
customFields: JSON
Returns element duration in seconds.
duration: Int
Returns time element was published as UNIX time in seconds.
publishedAt: Int64
Returns true if element has fixed duration.
fixedDuration: Bool
public var textDuringPoll: String?
public var textAfterAnswering: String?
public var textAfterPoll: String?
For a child of RevelablePoll Element:
public var textAfterReveal: String?
public var isRevealed: Bool
Children elements overwrite, use basic method
public func baseVote(optionIndexes: [Int]) -> Bool
public var hasUserVoted: Bool
Returns array where each element is an option index you've voted for.
userVote: [Int]?
Subscribe to element's changes.
onStateChanged: ((BasePoll.State) -> Void)?
onResults: ((Void) -> Void)?
onVote: ((Void) -> Void)?
If results are available they can be determined by
....
public typealias ElementResultType = [String: AnyObject]
public typealias ElementResultsType = [ElementResultType]
....
public var hasResults: Bool
public var results: ElementResultsType!
public var resultsPerSource: ElementResultsType!
Returned dictionaries might have keys from the structure:
public struct ElementResultKey {
public static let Votes = "votes"
public static let Percentage = "percentage"
public static let Source = "source"
public static let Voters = "voters"
public static let Results = "results"
public static let Volume = "volume"
public static let Average = "average"
public static let Time = "time"
}
Usually there is one question in a poll, but there can be several, in case of sliced poll Question index is defined by the following property:
public var questionIndex: Int = 0
Current question is determined by:
public var question: Question
All questions are determined by:
public var questions: [Question]
Options for current question are defined by:
public var options: [Option]
All answer options could be accessed by:
public var allOptions: [Option]
Options for specific question index can be accessed by:
public func getOptions(forQuestionIndex questionIndex: Int) -> [Option] {
If element can be in revealed state, it has Revealed state. Otherwise the state is not accessible.
public enum BasePoll.State: Int {
case Started = 0
case Stopped = 1
case Revealed = 2
}
For state detection there are some helper properties:
public var BasePoll.isStopped: Bool
public var RevelablePoll.isRevealed: Bool
Last modified 4yr ago