-
Notifications
You must be signed in to change notification settings - Fork 2
Model Binding
Karim Chang edited this page Sep 23, 2018
·
4 revisions
SwiftFFDB implementation of model binding based on the Codable protocol of Swift 4
create class or struct and implementation FFObject protocol:
class Person: FFObject {
var primaryID: Int64?
var name : String?
var sex : Bool?
var memoryColumn : String?
var age : Float?
required init() {
}
static func memoryPropertys() -> [String]? {
return nil
}
static func customColumnsType() -> [String : String]? {
return nil
}
static func customColumns() -> [String : String]? {
return nil
}
}
| SQLite type | Swift type |
|---|---|
| text | String |
| float | Float,Float32,Float64 |
| double | Double,Date |
| integer | Int,Int8,Int16,Int32,Int64 |
| Bool | Bool |
| text | Default |
| Blob | Data |
static func memoryPropertys() -> [String]? can help you overlook column,If you don't want to save memoryColumn in SQLite:
static func memoryPropertys() -> [String]? {
return ["memoryColumn"]
}
SwiftFFDB column have default mapping type,but is also can cnovert to other type,use static func customColumnsType() -> [String : String]?:
static func customColumnsType() -> [String : String]? {
return ["age":"integer"]
}
object can use func update(),func update(),because primaryID alway is PRIMARY KEY AUTOINCREMENT,if you don't want primaryID AUTOINCREMENT,you can implementation static func customColumnsType() -> [String : String]?:
static func customColumnsType() -> [String : String]? {
return ["primaryID":"integer"]
}
If you do this,you should be use FFDBManager
static func customColumns() -> [String : String]?can map column name:
static func customColumns() -> [String : String]? {
return ["name":"nick_name"]
}