Distinct 不适用于 Realm Objects 结果
Distinct is not working with Realm Objects results
我想根据 ID 获取不同的对象,但我做不到。我面临以下错误
Generic parameter 'S' could not be inferred
看看下面的图片,让我知道是什么问题请帮助我。我陷入其中
如果您查看 distinct(by:)
(func distinct<S>(by keyPaths: S) -> Results<Person> where S : Sequence, S.Element == String
) 的类型签名,您会发现它需要一个 Sequence<String>
类型的输入参数。此外,查看该方法的 documentation,它告诉您需要将 keyPaths 作为要使用的 String
s 传递,以产生不同的结果。
所以使用官方文档中的 Dog
class 示例,如果你想根据 name
属性 产生不同的结果,你的函数调用将看起来像这样:
class Dog: Object {
@objc dynamic var name = ""
@objc dynamic var age = 0
}
realm.objects(Dog.self).distinct(by: ["name"])
我想根据 ID 获取不同的对象,但我做不到。我面临以下错误
Generic parameter 'S' could not be inferred
看看下面的图片,让我知道是什么问题请帮助我。我陷入其中
如果您查看 distinct(by:)
(func distinct<S>(by keyPaths: S) -> Results<Person> where S : Sequence, S.Element == String
) 的类型签名,您会发现它需要一个 Sequence<String>
类型的输入参数。此外,查看该方法的 documentation,它告诉您需要将 keyPaths 作为要使用的 String
s 传递,以产生不同的结果。
所以使用官方文档中的 Dog
class 示例,如果你想根据 name
属性 产生不同的结果,你的函数调用将看起来像这样:
class Dog: Object {
@objc dynamic var name = ""
@objc dynamic var age = 0
}
realm.objects(Dog.self).distinct(by: ["name"])