Skip to content

Commit 038500e

Browse files
v2.14.1:
- Few cumulative fixes
1 parent b5d0209 commit 038500e

12 files changed

+56
-53
lines changed

Questions/AVAudioPlayer+Extension.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ extension AVAudioPlayer {
44

55
convenience init?(file: String, type: String) {
66

7-
let path = Bundle.main.path(forResource: file, ofType: type)
8-
let url = URL(fileURLWithPath: path!)
7+
guard let path = Bundle.main.path(forResource: file, ofType: type) else { print("Incorrect audio path"); return nil}
8+
9+
let url = URL(fileURLWithPath: path)
910

1011
try? self.init(contentsOf: url)
1112
}

Questions/Base.lproj/Main.storyboard

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Otc-Gn-hwi">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16F43c" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Otc-Gn-hwi">
33
<device id="retina5_5" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>

Questions/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.13-beta</string>
18+
<string>2.14.1-beta</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

Questions/MainViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class MainViewController: UIViewController {
8989
startButton.setTitle("START GAME".localized, for: .normal)
9090
readQRCodeButton.setTitle("READ QR CODE".localized, for: .normal)
9191
settingsButton.setTitle("SETTINGS".localized, for: .normal)
92-
self.navigationItem.title = "Main menu".localized
92+
navigationItem.title = "Main menu".localized
9393
}
9494

9595
func setFramesPositionAndSize() {
@@ -120,8 +120,8 @@ class MainViewController: UIViewController {
120120
}
121121

122122
func loadTheme() {
123-
self.navigationController?.navigationBar.barStyle = .themeStyle(dark: .black, light: .default)
124-
self.navigationController?.navigationBar.tintColor = .themeStyle(dark: .orange, light: .defaultTintColor)
123+
navigationController?.navigationBar.barStyle = .themeStyle(dark: .black, light: .default)
124+
navigationController?.navigationBar.tintColor = .themeStyle(dark: .orange, light: .defaultTintColor)
125125
}
126126

127127
static func addParallax(toView view: UIView?) {

Questions/QRScannerViewController.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ class QRScannerViewController: UIViewController, AVCaptureMetadataOutputObjectsD
1919
allowCameraButton.setTitle("Allow camera access".localized, for: .normal)
2020

2121
let captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
22-
let input: AVCaptureInput?
23-
24-
do { input = try AVCaptureDeviceInput(device: captureDevice) }
25-
catch { return }
22+
23+
guard let input = try? AVCaptureDeviceInput(device: captureDevice) else { return }
2624

2725
let captureSession = AVCaptureSession()
2826
captureSession.addInput(input)
@@ -60,11 +58,12 @@ class QRScannerViewController: UIViewController, AVCaptureMetadataOutputObjectsD
6058

6159
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) {
6260

63-
if !codeIsRead {
64-
65-
let metadataObject = metadataObjects.first as? AVMetadataMachineReadableCodeObject
61+
let metadataObject = metadataObjects.first as? AVMetadataMachineReadableCodeObject
62+
63+
guard !codeIsRead, let metadata = metadataObject else { return }
64+
65+
if metadata.type == AVMetadataObjectTypeQRCode {
6666

67-
guard let metadata = metadataObject, metadata.type == AVMetadataObjectTypeQRCode else { invalidQRCodeFormat(); return }
6867
guard let data = metadata.stringValue.data(using: .utf8) else { invalidQRCodeFormat(); return }
6968

7069
var content: [[String: Any]]?

Questions/QuestionsViewController.swift

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -88,29 +88,28 @@ class QuestionsViewController: UIViewController {
8888
// If user shake the device, an alert to repeat the quiz pop ups
8989
override func motionEnded(_ motion: UIEventSubtype, with event: UIEvent?) {
9090

91-
if motion == .motionShake {
91+
guard motion == .motionShake else { return }
92+
93+
let currentQuestion = Int(String(remainingQuestionsLabel.text?.characters.first ?? "0")) ?? 0
94+
95+
if #available(iOS 10.0, *), Settings.sharedInstance.hapticFeedbackEnabled {
96+
let feedbackGenerator = UIImpactFeedbackGenerator(style: .medium)
97+
feedbackGenerator.impactOccurred()
98+
}
99+
100+
if repeatTimes < 2 && currentQuestion > 1 {
92101

93-
let currentQuestion = Int(String(remainingQuestionsLabel.text?.characters.first ?? "0")) ?? 0
102+
let alertViewController = UIAlertController(title: "Repeat?".localized,
103+
message: "Do you want to start again?".localized,
104+
preferredStyle: .alert)
94105

95-
if repeatTimes < 2 && currentQuestion > 1 {
96-
97-
if #available(iOS 10.0, *), Settings.sharedInstance.hapticFeedbackEnabled {
98-
let feedbackGenerator = UIImpactFeedbackGenerator(style: .medium)
99-
feedbackGenerator.impactOccurred()
100-
}
101-
102-
let alertViewController = UIAlertController(title: "Repeat?".localized,
103-
message: "Do you want to start again?".localized,
104-
preferredStyle: .alert)
105-
106-
alertViewController.addAction(title: "OK".localized, style: .default) { action in self.repeatActionDetailed() }
107-
alertViewController.addAction(title: "Cancel".localized, style: .cancel, handler: nil)
108-
109-
present(alertViewController, animated: true, completion: nil)
110-
}
111-
else if repeatTimes >= 2 {
112-
showOKAlertWith(title: "Attention", message: "Maximum help tries per question reached")
113-
}
106+
alertViewController.addAction(title: "OK".localized, style: .default) { action in self.repeatActionDetailed() }
107+
alertViewController.addAction(title: "Cancel".localized, style: .cancel, handler: nil)
108+
109+
present(alertViewController, animated: true, completion: nil)
110+
}
111+
else if repeatTimes >= 2 {
112+
showOKAlertWith(title: "Attention", message: "Maximum help tries per question reached")
114113
}
115114
}
116115

@@ -313,7 +312,7 @@ class QuestionsViewController: UIViewController {
313312
answerButtons[2].frame = CGRect(x: xPosition, y: yPosition4 - fullLabelHeight, width: labelWidth, height: labelHeight)
314313
answerButtons[3].frame = CGRect(x: xPosition, y: yPosition4, width: labelWidth, height: labelHeight)
315314

316-
let currentStatusBarHeight = isPortrait ? self.statusBarHeight : 0.0
315+
let currentStatusBarHeight = isPortrait ? statusBarHeight : 0.0
317316
let yPosition6 = ((yPosition / 2.0) - labelHeight) + currentStatusBarHeight + (pauseButton.bounds.height / 2.0)
318317
questionLabel.frame = CGRect(x: xPosition, y: yPosition6, width: labelWidth, height: labelHeight * 2)
319318

@@ -347,7 +346,7 @@ class QuestionsViewController: UIViewController {
347346
}
348347
}
349348
else {
350-
self.endOfQuestionsAlert()
349+
endOfQuestionsAlert()
351350
}
352351
}
353352

@@ -414,7 +413,7 @@ class QuestionsViewController: UIViewController {
414413
self.answerButtons[Int(answer)].backgroundColor = .themeStyle(dark: .orange, light: .defaultTintColor)
415414
}
416415

417-
self.pickQuestion()
416+
pickQuestion()
418417
}
419418

420419
func pausePreviousSounds() {

Questions/Quiz.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ import Foundation
33
struct Quiz {
44

55
private(set) var name = String()
6-
private(set) var content: [[[String: Any]]]!
6+
private(set) var content = [[[String: Any]]]()
77

88
init(name: String) {
9+
910
self.name = name
1011

11-
let path = Bundle.main.path(forResource: name, ofType: "json")
12-
let url = URL(fileURLWithPath: path!)
12+
guard let path = Bundle.main.path(forResource: name, ofType: "json") else { print("Quiz incorrect path"); return }
13+
let url = URL(fileURLWithPath: path)
1314

14-
if let data = try? Data(contentsOf: url) {
15-
content = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as! [[[String: Any]]]
15+
do {
16+
let data = try Data(contentsOf: url)
17+
content = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as! [[[String: Any]]]
18+
} catch {
19+
print("Error initializing quiz content")
1620
}
1721
}
18-
22+
1923
static let quizzes = [Quiz(name: "Technology"), Quiz(name: "Social"), Quiz(name: "People")]
2024
}

Questions/QuizzesViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class QuizzesViewController: UITableViewController {
1212
override func viewDidLoad() {
1313
super.viewDidLoad()
1414

15-
self.navigationItem.title = Quiz.quizzes[currentTopicIndex].name.localized
15+
navigationItem.title = Quiz.quizzes[currentTopicIndex].name.localized
1616
setCount = Quiz.quizzes[currentTopicIndex].content.count
1717

1818
NotificationCenter.default.addObserver(self, selector: #selector(loadCurrentTheme),
@@ -110,8 +110,8 @@ class QuizzesViewController: UITableViewController {
110110
// MARK: Convenience
111111

112112
func loadCurrentTheme() {
113-
self.navigationController?.navigationBar.barStyle = .themeStyle(dark: .black, light: .default)
114-
self.navigationController?.navigationBar.tintColor = .themeStyle(dark: .orange, light: .defaultTintColor)
113+
navigationController?.navigationBar.barStyle = .themeStyle(dark: .black, light: .default)
114+
navigationController?.navigationBar.tintColor = .themeStyle(dark: .orange, light: .defaultTintColor)
115115
tableView.backgroundColor = .themeStyle(dark: .darkGray, light: .groupTableViewBackground)
116116
tableView.separatorColor = .themeStyle(dark: .darkGray, light: .defaultSeparatorColor)
117117
tableView.reloadData()

Questions/Settings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22

33
class Settings: NSObject, NSCoding {
44

5-
static let path = "\(Settings.documentsDirectory())/Settings.archive"
5+
static let path = Settings.documentsDirectory() + "/Settings.archive"
66
var completedSets: [Int:[Bool]] = [:]
77
var correctAnswers: Int = 0
88
var incorrectAnswers: Int = 0

Questions/SettingsViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class SettingsViewController: UITableViewController {
199199
}
200200

201201
func loadTheme() {
202-
self.darkThemeSwitch.setOn(Settings.sharedInstance.darkThemeEnabled, animated: false)
202+
darkThemeSwitch.setOn(Settings.sharedInstance.darkThemeEnabled, animated: false)
203203
loadCurrentTheme(animated: false)
204204
}
205205

@@ -213,7 +213,7 @@ class SettingsViewController: UITableViewController {
213213
}
214214
}
215215
else { // On iOS 9, the barStyle animation is not very nice...
216-
self.navigationController?.navigationBar.barStyle = .themeStyle(dark: .black, light: .default)
216+
navigationController?.navigationBar.barStyle = .themeStyle(dark: .black, light: .default)
217217
}
218218

219219
UIView.animate(withDuration: duration) {

0 commit comments

Comments
 (0)