领域列表过滤器Swift

时间:2016-11-14 15:30:12

标签: swift realm

var numbersDetail = List is type of ContactDetail()
let predicate = NSPredicate(format: ContactDetail.NUMBER + " = %@", formattedNumber!)
let realmContactDetail = numbersDetail.filter(predicate).first

获取错误:

  

抛出RLMException(“此方法只能在RLMArray上调用   从RLMRealm“)中检索的实例;

1 个答案:

答案 0 :(得分:1)

如果在将父对象添加到{之前尝试对Realm Swift List对象(实际上是Objective-C RLMArray对象)执行查询,则会发生此错误{1}}。

Realm

简而言之,在执行该查询之前,您需要确保class Person: Object { dynamic var name = "" dynamic var picture: NSData? = nil // optionals supported let dogs = List<Dog>() } let dog = Dog() dog.name = "Rex" let person = Person() person.dogs.append(dog) let rex = person.dogs.filter("name == 'Rex'") // QUERY WILL TRIGGER EXCEPTION AT THIS POINT let realm = try! Realm() try! realm.write { realm.add(person) } let rex = person.dogs.filter("name == 'Rex'") // Query will now work as expected 属于numbersDetail。您可以通过选中Realm

轻松测试