XMLCoder Documentation

Enumeration XMLEncoder.​Key​Encoding​Strategy

public enum KeyEncodingStrategy  

The strategy to use for automatically changing the value of keys before encoding.

Member Of

XMLEncoder

XMLEncoder facilitates the encoding of Encodable values into XML.

Enumeration Cases

use​Default​Keys

case useDefaultKeys

Use the keys specified by each type. This is the default strategy.

convert​ToSnake​Case

case convertToSnakeCase

Convert from "camelCaseKeys" to "snake_case_keys" before writing a key to XML payload.

Capital characters are determined by testing membership in CharacterSet.uppercaseLetters and CharacterSet.lowercaseLetters (Unicode General Categories Lu and Lt). The conversion to lower case uses Locale.system, also known as the ICU "root" locale. This means the result is consistent regardless of the current user's locale and language preferences.

Converting from camel case to snake case:

  1. Splits words at the boundary of lower-case to upper-case
  2. Inserts _ between words
  3. Lowercases the entire string
  4. Preserves starting and ending _.

For example, oneTwoThree becomes one_two_three. _oneTwoThree_ becomes _one_two_three_.

convert​ToKebab​Case

case convertToKebabCase

Same as convertToSnakeCase, but using - instead of _ For example, oneTwoThree becomes one-two-three.

capitalized

case capitalized

Capitalize the first letter only oneTwoThree becomes OneTwoThree

uppercased

case uppercased

Uppercase ize all letters oneTwoThree becomes ONETWOTHREE

lowercased

case lowercased

Lowercase all letters oneTwoThree becomes onetwothree

custom

case custom((_ codingPath: [CodingKey]) -> CodingKey) 

Provide a custom conversion to the key in the encoded XML from the keys specified by the encoded types. The full path to the current encoding position is provided for context (in case you need to locate this key within the payload). The returned key is used in place of the last component in the coding path before encoding. If the result of the conversion is a duplicate key, then only one value will be present in the result.