This repository has been archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.swift
76 lines (60 loc) · 1.98 KB
/
Settings.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// Settings.swift
// Bomberman
//
// Created by Wolfgang Schreurs on 07/08/16.
//
//
import Foundation
class Settings {
static let kLevelKey = "level"
static let kMusicKey = "music"
static let kAssetsCheckKey = "assetsCheck"
static let kShowMenuOnStartupKey = "showMenuOnStartup"
// MARK: - Private
fileprivate static func setBool(_ flag: Bool, forKey key: String) {
let userDefaults = UserDefaults.standard
userDefaults.set(flag, forKey: key)
userDefaults.synchronize()
}
fileprivate static func boolForKey(_ key: String) -> Bool {
let userDefaults = UserDefaults.standard
let flag = userDefaults.bool(forKey: key)
return flag
}
fileprivate static func setInteger(_ int: Int, forKey key: String) {
let userDefaults = UserDefaults.standard
userDefaults.set(int, forKey: key)
userDefaults.synchronize()
}
fileprivate static func integerForKey(_ key: String) -> Int {
let userDefaults = UserDefaults.standard
let int = userDefaults.integer(forKey: key)
return int
}
// MARK: - Public
static func setInitialLevel(_ index: Int) {
setInteger(index, forKey: kLevelKey)
}
static func initialLevel() -> Int {
return integerForKey(kLevelKey)
}
static func setMusicEnabled(_ enabled: Bool) {
setBool(enabled, forKey: kMusicKey)
}
static func musicEnabled() -> Bool {
return boolForKey(kMusicKey)
}
static func setAssetsCheckEnabled(_ enabled: Bool) {
setBool(enabled, forKey: kAssetsCheckKey)
}
static func assetsCheckEnabled() -> Bool {
return boolForKey(kAssetsCheckKey)
}
static func setShowMenuOnStartupEnabled(_ enabled: Bool) {
setBool(enabled, forKey: kShowMenuOnStartupKey)
}
static func showMenuOnStartupEnabled() -> Bool {
return boolForKey(kShowMenuOnStartupKey)
}
}