kangarooChris kangarooChris - 4 months ago 21
Swift Question

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.

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? I tried to define 'results' as

var results = [Table]()


but that does not work.

Answer

You can option-click on results to view the inferred type.

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).

Comments