realm-swift
realm-swift copied to clipboard
RCOCOA-2271: Collections in Mixed
-
Added support for storing nested collections (List and Map not ManagedSet) in a
AnyRealmValue
.class MixedObject: Object { @Persisted var anyValue: AnyRealmValue } // You can build a AnyRealmValue from a Swift's Dictionary. let dictionary: Dictionary<String, AnyRealmValue> = ["key1": .string("hello"), "key2": .bool(false)] // You can build a AnyRealmValue from a Swift's Map // and nest a collection within another collection. let list: Array<AnyRealmValue> = [.int(12), .double(14.17), AnyRealmValue.fromDictionary(dictionary)] let realm = realmWithTestPath() try realm.write { let obj = MixedObject() obj.anyValue = AnyRealmValue.fromArray(list) realm.add(o) }
-
Added new operators to Swift's Query API for supporting querying nested collections.
realm.objects(MixedObject.self).where { $0.anyValue[0][0][1] == .double(76.54) }
The
.all
operator allows looking up in all keys or indexes.realm.objects(MixedObject.self).where { $0.anyValue["key"].all == .bool(false) }
This is waiting for this PR to be merged to core. Also, there is one failing test which is working locally, taking a look at it, but putting this on review on the meantime.
@tgoyne and @leemaguire solved pr comments and there are some comments as well
There are a bunch of new warnings here that need to be fixed.
@tgoyne solved PR comments and removed the warnings