I have some table provider classes that conform to UITableViewDataSource/Delegate and are powered by Realm. These classes currently use a var objects: Results<MyObject>? variable to hold onto the list of objects. This list is provided by the VC before the table is displayed.
It's unfortunate that I need to use an optional here, but there is no way to provide a default value. If they were using a List instead, I could use var objects = List<MyObject>() and create a dummy list.
It would be nice if there were a method that made an empty Results, e.g., var objects = Results<MyObject>() (or whatever y'all think is best).
I could yolo and use an IUO, but that's Bad Swiftâ„¢.
There's some way to generate a Results object without actually putting any data inside.
Maybe this is just a bad way to power tables off of Realm? What's the best practice here?
Using an IUO isn't bad swift, that's exactly the use case it's intended to serve.
If you really need an empty Results, you can do realm.objects(Model.self).filter("FALSEPREDICATE"). Unlike List and Object subclasses, Results can never be unmanaged.
Ah, hmm. Ok! An IUO it is then! Thanks!