realm 迅速
示例
创建对象类:
class Dog: Object { dynamic var name = "" dynamic var age = 0 }
分配对象的值:
let dog = Dog() dog.name = "Rex" dog.age = 1
保存对象:
let realm = try! Realm() try!realm.write{ realm.add(dog) }
读取对象:
let realm = try! Realm() let pups = realm.objects(Dog.self)
过滤对象:
let realm = try! Realm() let filteredPups = realm.objects(Dog.self).filter("age < 2")
计数对象:
let realm = try! Realm() let pupsCount = realm.objects(Dog.self).count