-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.swift
63 lines (55 loc) · 1.17 KB
/
main.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
import SQLiteStORM
SQLiteConnector.db = "./gamescores"
// setup games
let gameSetup = Game()
try? gameSetup.setup()
// setup scores
let scoreSetup = Score()
try? scoreSetup.setup()
// comment out after first run
gameSetup.name = "Hello World"
do {
gameSetup.id = try gameSetup.save() as? Int ?? 0
} catch {
print("gameSetup error: \(error)")
}
var scoreSetup1 = Score()
scoreSetup1.game = gameSetup.id
scoreSetup1.user = "Joe"
scoreSetup1.score = 100
do {
try scoreSetup1.save()
} catch {
print("scoreSetup1 error: \(error)")
}
var scoreSetup2 = Score()
scoreSetup2.game = gameSetup.id
scoreSetup2.user = "Jane"
scoreSetup2.score = 102
do {
try scoreSetup2.save()
} catch {
print("scoreSetup2 error: \(error)")
}
var scoreSetup3 = Score()
scoreSetup3.game = gameSetup.id
scoreSetup3.user = "Andrea"
scoreSetup3.score = 101
do {
try scoreSetup3.save()
} catch {
print("scoreSetup3 error: \(error)")
}
// end populate
let gameTest = Game()
do {
try gameTest.get(gameSetup.id)
} catch {
print("gameTest.get error: \(error)")
}
print("Game ID: \(gameTest.id)")
print("Game Name: \(gameTest.name)")
gameTest._scores.forEach{
score in
print("Score: \(score.user), \(score.score)")
}