1
如何創建Realm DB?我已經通過CocoaPods爲swift安裝了Realm(> = 3.0)。我試圖創建一個簡單的數據庫,將保持最多20個對象。我創建一個類數據庫():使用Realm創建數據庫Swift 3.0.1
import RealmSwift
class DataBase: Object{
dynamic var code: String = ""
dynamic var desc: String = ""
dynamic var capture: [UIImage] = []
dynamic var lon: Double = 0.0
dynamic var lat: Double = 0.0
dynamic var type: Int = 0
}
而且我想一個對象添加到數據庫:
let offlineInfo = DataBase()
let realm = try! Realm()
offlineInfo.code = "testCode"
offlineInfo.desc = "testDescription"
offlineInfo.capture = self.capture
offlineInfo.lat = self.lat
offlineInfo.lon = self.lon
offlineInfo.type = 2
try! realm.write {
realm.add(offlineInfo)
}
但我有創造「offlineInfo」對象時,SIGABRT錯誤和不肯定我做得正確。而且即使我退出應用程序,數據庫也會保存嗎?
你可以添加你得到的確切的錯誤? –