Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

URLEncodedFormEncoder_KeyEncoding

mattt edited this page Sep 18, 2020 · 2 revisions

URLEncodedFormEncoder.KeyEncoding

Encoding to use for keys.

public enum KeyEncoding

This type is derived from JSONEncoder's KeyEncodingStrategy and XMLEncoders KeyEncodingStrategy.

Enumeration Cases

useDefaultKeys

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

case useDefaultKeys

convertToSnakeCase

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

case convertToSnakeCase

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_.

convertToKebabCase

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

case convertToKebabCase

capitalized

Capitalize the first letter only. For example oneTwoThree becomes OneTwoThree.

case capitalized

uppercased

Uppercase all letters. For example oneTwoThree becomes ONETWOTHREE.

case uppercased

lowercased

Lowercase all letters. For example oneTwoThree becomes onetwothree.

case lowercased

custom

A custom encoding using the provided closure.

case custom(:(String) -> String)
Types
Protocols
Global Typealiases
Clone this wiki locally