Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an empty Results<T> object?

Tags:

ios

swift

realm

I'm trying to create a MutableProperty which holds a Results received from Realm.objects(_:). To create the property I need to give it an initial value; hence an 'empty' Results.

I've tried creating one using:

var someThings = Results<SomeObject>()
MutableProperty(someThings)

But the compiler gives me the error: Cannot invoke initializer for type 'Results<SomeObject>' with no arguments.

While I understand the error, I'm not really sure how to create a Results object in this context. Looking at the source of Results I couldn't find an init either.


So my question is; how can I create a Results myself to use in a MutableProperty?

Edit:

I've seen this question...but that doesn't really help (unless I'm going to create a "wrapper" for the MutableProperty or something).

like image 691
Gee.E Avatar asked Oct 18 '22 09:10

Gee.E


1 Answers

With help of the comments on my OP; I created a mutable property with an empty set of results by fetching objects with an 'invalid' filter.

E.g. MutableProperty(realm.objects(SomeObject.self).filer("EMPTY SET")).

like image 90
Gee.E Avatar answered Nov 15 '22 07:11

Gee.E