【发布时间】:2016-11-03 10:21:13
【问题描述】:
如果id 为 nil 或为空,我想过滤领域结果列表。
这是一个演示结果列表:
{
"id":"1"
"name": "first"
},
{
"id":"2"
"name": "second"
},
{
"id":"3"
"name": "third"
},
{
"id":"" //here it can be empty
"name": ""
},
{
"id": nil // here it can be nil
"name": nil
}
我尝试使用这样的 id 进行过滤,但它崩溃了:
lazy var declarations: Results<Declaration> = {
let realm = try! Realm()
return self.realm.objects(Declaration.self).filter("id == " "")
}()
这是模型:
import RealmSwift
public final class Declaration: Object {
dynamic var id: String = ""
dynamic var name: String = ""
override public static func primaryKey() -> String? {
return "id"
}
}
【问题讨论】: