predicate realm bool swift code example

Example: predicate realm bool swift

import RealmSwift

class User: Object {
    dynamic var isRegistered = true
}

let realm = Realm()
realm.write {
    realm.add(User())
}
let p1 = NSPredicate(format: "isRegistered == YES")
let p2 = NSPredicate(format: "isRegistered == true")
let p3 = NSPredicate(format: "isRegistered == %@", NSNumber(bool: true))
let p4 = NSPredicate(format: "isRegistered = YES")
let p5 = NSPredicate(format: "isRegistered = true")
let p6 = NSPredicate(format: "isRegistered = %@", NSNumber(bool: true))
for predicate in [p1, p2, p3, p4, p5, p6] {
    println("users matching \(predicate): \(realm.objects(User).filter(predicate))")
}