2 / 4
Jun 2024

I am sure the documentation will be updated so I am likely jumping the gun a bit but can we have more information or perhaps a use case on the new AnyRealmValue options for mixed objects?

The documentation is currently a bit thin on AnyRealmValue so additional info would be great!

  • 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 .any operator allows looking up in all keys or indexes.

realm.objects(MixedObject.self).where { $0.anyValue[“key”].any == .bool(false) }`

  1. What would be a use case for this [0][0][1]?

  2. an example query for this: $0.anyValue[“key”].any == .bool(false) may clarify use (e.g. “key”?)

  3. and then maybe clarification on how RealmStudio stores this object.

For example, when the object in the example code above is written

let dictionary: Dictionary<String, AnyRealmValue> = ["key1": .string("hello"), "key2": .bool(false)] 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(obj) }

read back

let obj = realm.objects(MixedObject.self).first! let element0 = obj.anyValue.listValue![0] let element1 = obj.anyValue.listValue![1] let element2 = obj.anyValue.listValue![2].dictionaryValue! print(element0) print(element1) print(element2)

and output to console. it returns the following - which appears to match

int(12) double(14.17) Map<string, mixed> <0x6000019bc540> ( [key1]: hello, [key2]: 0 )

But Realm Studio 15.1.1 (15.1.1) shows this

the key"key1" has a value of “2” instead of “hello” and “hello” is the last element of the list?

@Kenneth_Geisshirt

That would be great! It’s not mission critical as the functionality works but it would be helpful to view it in a readable format.

I think some additional clarity on the use-case of the new feature would really be helpful to developers going forward.