← All repositories

reportage

A life-logging app for iPhone

git clone https://code.inqk.net/reportage.git


Shared/Models/Question.swift (1973B)

1import Foundation
2
3/// A survey question. Questions are archived rather than deleted so that the
4/// responses recorded against them keep their meaning.
5struct Question: Hashable, Sendable {
6    /// Imported questions keep Reporter's `uniqueIdentifier` (for example
7    /// `default-question-2`); new questions use UUID strings.
8    var id: String
9    var prompt: String
10    var kind: QuestionKind
11    /// The fixed answer list for `choice` questions. Empty for other kinds.
12    var options: [String] = []
13    var placeholder: String?
14    /// How answers read in a narrative. `nil` uses the rule the kind implies.
15    var narrativeRule: NarrativeRule?
16    /// The surveys the question appears in.
17    var askOn: SurveyKinds
18    /// Sort order within a survey, and the order its answers read in a
19    /// narrative.
20    var order: Int
21    /// Whether the question's answers appear in the timeline. Hidden answers
22    /// are still shown in the report's details.
23    var showsInTimeline = true
24    var archivedAt: Date?
25    var modifiedAt: Date
26}
27
28enum QuestionKind: String, Codable, Sendable, CaseIterable {
29    case yesNo
30    case choice
31    case tokens
32    case people
33    case location
34    case number
35    case note
36}
37
38/// The set of surveys a question is asked in. Manual reports use the random
39/// survey, so there is no separate member for them.
40struct SurveyKinds: OptionSet, Hashable, Sendable {
41    let rawValue: Int16
42
43    static let random = SurveyKinds(rawValue: 1 << 0)
44    static let wake = SurveyKinds(rawValue: 1 << 1)
45    static let bedtime = SurveyKinds(rawValue: 1 << 2)
46
47    static let all: SurveyKinds = [.random, .wake, .bedtime]
48
49    /// The survey a report of the given kind presents.
50    init(surveyFor kind: ReportKind) {
51        switch kind {
52        case .random, .manual: self = .random
53        case .wake: self = .wake
54        case .bedtime: self = .bedtime
55        }
56    }
57
58    init(rawValue: Int16) {
59        self.rawValue = rawValue
60    }
61}