MapKey

public protocol MapKey

A MapKey is a protocol that provides a parsing mechanism for converting any object (such as a String) into key parts (an array of KeyPart objects). Key parts individually represent a key in a JSON dictionary or position in a JSON array. When combined, key parts represent the nesting structure of a JSON dictionary for a specific value, object or array. The order of key parts matter as they coencide with the nesting order in a dictionary.

For example, lets say we are given the following key parts: 1 KeyPart.object("first") 2 KeyPart.array("second") 3 KeyPart.object("first")

This can be used to return the value My Value from the nested key first in the following JSON dictionary:

{
   "first": {
       "second": [
           {
               "first": "My Value"
           }
       ]
   }
}

Using this key when storing a value in the map will, on the other hand, create the above JSON dictionary.

JSON dictionaries created using key parts are merged when the key part does not represent a leaf in a JSON dictionary.

For example, if I were to add the value My other value to the above JSON using the following key parts: 1 KeyPart.object("first") 2 KeyPart.array("second") 3 KeyPart.object("second")

Then i will end up with the following result:

{
   "first": {
       "second": [
           {
               "first": "My Value"
               "second": "My other Value"
           }
       ],
   }
}
  • Returns the raw representation (human readable String) of the MapKey.

    Declaration

    Swift

    var rawValue: String { get }
  • A method that parses the object into key parts (an array of KeyPart)

    Declaration

    Swift

    func parseKeyParts() throws -> [KeyPart]