简体   繁体   English

Realm Swift中查询的类型是什么?

[英]what is the type of a query in Realm Swift?

I have the result of a query in Realm and now I'd like to use 'results' as a global variable. 我在Realm中有查询的结果,现在我想将'results'用作全局变量。

let results = self.realm.objects(Table)

What actually is the type of 'results' in above example? 上面示例中的“结果”实际上是什么类型? In the documentation it says that Queries return a Result instance, but what does that mean in regards to the type? 在文档中,它说查询返回了一个Result实例,但这对类型意味着什么? I tried to define 'results' as 我试图将“结果”定义为

var results = [Table]()

but that does not work. 但这不起作用。

You can option-click on results to view the inferred type. 您可以选择单击results以查看推断的类型。

In this case, if you look at the documentation for objects(_:) , you'll see that it returns a Results<T> , where T is the type speicifed by the parameter ( Table , in this case). 在这种情况下,如果查看objects(_:)的文档,则会看到它返回一个Results<T> ,其中T是参数指定的类型(在这种情况下为Table )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM