mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
51 lines
1.6 KiB
Swift
51 lines
1.6 KiB
Swift
import GRDBCipher
|
|
|
|
class Person: Record {
|
|
var id: Int64?
|
|
var name: String
|
|
var score: Int
|
|
|
|
init(name: String, score: Int) {
|
|
self.name = name
|
|
self.score = score
|
|
super.init()
|
|
}
|
|
|
|
// MARK: Record overrides
|
|
|
|
override class func databaseTableName() -> String {
|
|
return "persons"
|
|
}
|
|
|
|
required init(_ row: Row) {
|
|
id = row.value(named: "id")
|
|
name = row.value(named: "name")
|
|
score = row.value(named: "score")
|
|
super.init(row)
|
|
}
|
|
|
|
override var persistentDictionary: [String : DatabaseValueConvertible?] {
|
|
return [
|
|
"id": id,
|
|
"name": name,
|
|
"score": score]
|
|
}
|
|
|
|
override func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
|
id = rowID
|
|
}
|
|
|
|
// MARK: Random
|
|
|
|
private static let names = ["Arthur", "Anita", "Barbara", "Bernard", "Craig", "Chiara", "David", "Dean", "Éric", "Elena", "Fatima", "Frederik", "Gilbert", "Georgette", "Henriette", "Hassan", "Ignacio", "Irene", "Julie", "Jack", "Karl", "Kristel", "Louis", "Liz", "Masashi", "Mary", "Noam", "Nicole", "Ophelie", "Oleg", "Pascal", "Patricia", "Quentin", "Quinn", "Raoul", "Rachel", "Stephan", "Susie", "Tristan", "Tatiana", "Ursule", "Urbain", "Victor", "Violette", "Wilfried", "Wilhelmina", "Yvon", "Yann", "Zazie", "Zoé"]
|
|
|
|
class func randomName() -> String {
|
|
return names[Int(arc4random_uniform(UInt32(names.count)))]
|
|
}
|
|
|
|
class func randomScore() -> Int {
|
|
return 10 * Int(arc4random_uniform(101))
|
|
}
|
|
|
|
}
|