This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Question: Codable { | |
| var questionText: String | |
| var weightedAnswer: Double | |
| var selectedIndex: Int? = nil | |
| var valuesYes: [ValueItem] | |
| var valuesNo: [ValueItem] | |
| var imageName: String | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Question(questionText: questionTexts["qc4"]!, | |
| weightedAnswer: 0, | |
| valuesYes: [ValueItem(axis: "c0", value: 3)], | |
| valuesNo: [ValueItem(axis: "c1", value: 3)], | |
| imageName: "qc2-criminal") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var axes = [String : (Double, Double)](); | |
| for question in shuffled { | |
| for valueYes in question.valuesYes { | |
| if axes[valueYes.axis] == nil { | |
| axes[valueYes.axis] = (0, 0) | |
| } | |
| if question.weightedAnswer > 0 { | |
| axes[valueYes.axis]?.0 += | |
| question.weightedAnswer * Double(valueYes.value) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| results["c"] = ResultValues(Int(((axes["c0"]!.0) / (axes["c0"]!.1) * | |
| 100).rounded()), Int(((axes["c1"]!.0) / (axes["c1"]!.1) * | |
| 100).rounded())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let isMovingBack = currentQuestionNumber < oldValue | |
| let animationDistance: CGFloat = (self.view.bounds.width + | |
| self.questionCard.bounds.width) / 2 * (isMovingBack ? -1 : 1) | |
| UIView.animate(withDuration: 0.4, delay: 0.1, | |
| usingSpringWithDamping: 1, initialSpringVelocity: 0, | |
| options: [.curveLinear], animations: { | |
| self.questionCard.transform = | |
| CGAffineTransform(translationX: -animationDistance, y: 0) | |
| }) { (_) in | |
| self.questionCard.transform = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let soundEffectRow = SettingsSwitchRowView(withTitle: "Sound effects", | |
| isOn: (defaults.value(forKey: "soundEffectOn") as? Bool) ?? true, | |
| didToggle: { toggle in | |
| self.defaults.set(toggle.isOn, forKey: "soundEffectOn") | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ "t": ResultValues(l: 45, r: 14), | |
| "j": ResultValues(l: 26, r: 50), | |
| "m": ResultValues(l: 31, r: 38), | |
| "e": ResultValues(l: 48, r: 31), | |
| "c": ResultValues(l: 36, r: 38), | |
| ...... ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ ResultValues(l: 45, n: 41, r: 14), | |
| ResultValues(l: 26, n: 24, r: 50), | |
| ResultValues(l: 31, n: 31, r: 38), | |
| ResultValues(l: 48, n: 21, r: 31), | |
| ResultValues(l: 36, n: 26, r: 38), | |
| ...... ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| l = [45, 26, 31, 48, 36, ...] | |
| n = [41, 24, 31, 21, 26, ...] | |
| r = [14, 50, 38, 31, 38, ...] |