v24
Elements Common API
Votable polls are subclasses of BasePoll class. This class should be used in code for generalization.
1
public class BasePoll: Frame
Copied!
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.
1
public class RevelablePoll: BasePoll
Copied!
RevelablePoll class contains methods for accessing Revealed state, if a poll has it.

Get id

Returns element id.
1
id: String
Copied!

Get type

Returns element type.
1
type: String
Copied!

Get content type

Returns element content type.
1
contentType: String
Copied!

Get custom fields

Returns element custom fields as JSON.
1
customFields: JSON
Copied!

Get duration

Returns element duration in seconds.
1
duration: Int
Copied!

Get published time

Returns time element was published as UNIX time in seconds.
1
publishedAt: Int64
Copied!

Has fixed duration

Returns true if element has fixed duration.
1
fixedDuration: Bool
Copied!

Prompt during/ after voting

1
public var textDuringPoll: String?
2
public var textAfterAnswering: String?
3
public var textAfterPoll: String?
Copied!
For a child of RevelablePoll Element:
1
public var textAfterReveal: String?
2
public var isRevealed: Bool
Copied!

Voting and results

Children elements overwrite, use basic method
1
public func baseVote(optionIndexes: [Int]) -> Bool
2
public var hasUserVoted: Bool
Copied!
Returns array where each element is an option index you've voted for.
1
userVote: [Int]?
Copied!

Closures

Subscribe to element's changes.
1
onStateChanged: ((BasePoll.State) -> Void)?
2
onResults: ((Void) -> Void)?
3
onVote: ((Void) -> Void)?
Copied!

Results

If results are available they can be determined by
1
....
2
public typealias ElementResultType = [String: AnyObject]
3
public typealias ElementResultsType = [ElementResultType]
4
....
5
6
public var hasResults: Bool
7
public var results: ElementResultsType!
8
public var resultsPerSource: ElementResultsType!
Copied!
Returned dictionaries might have keys from the structure:
1
public struct ElementResultKey {
2
public static let Votes = "votes"
3
public static let Percentage = "percentage"
4
public static let Source = "source"
5
public static let Voters = "voters"
6
public static let Results = "results"
7
public static let Volume = "volume"
8
public static let Average = "average"
9
public static let Time = "time"
10
}
Copied!

Questions & Answers

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:
1
public var questionIndex: Int = 0
Copied!
Current question is determined by:
1
public var question: Question
Copied!
All questions are determined by:
1
public var questions: [Question]
Copied!
Options for current question are defined by:
1
public var options: [Option]
Copied!
All answer options could be accessed by:
1
public var allOptions: [Option]
Copied!
Options for specific question index can be accessed by:
1
public func getOptions(forQuestionIndex questionIndex: Int) -> [Option] {
Copied!

State

If element can be in revealed state, it has Revealed state. Otherwise the state is not accessible.
1
public enum BasePoll.State: Int {
2
case Started = 0
3
case Stopped = 1
4
case Revealed = 2
5
}
Copied!
For state detection there are some helper properties:
1
public var BasePoll.isStopped: Bool
2
public var RevelablePoll.isRevealed: Bool
Copied!
Last modified 2yr ago