0
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"
}
}