|
| 1 | +# CodingKey Macros Documentation |
| 2 | + |
| 3 | +## @CustomCodable |
| 4 | + |
| 5 | +Prerequisite for customizing CodingKeys |
| 6 | + |
| 7 | +```swift |
| 8 | +@Codable |
| 9 | +struct MyType: Codable { |
| 10 | +} |
| 11 | +``` |
| 12 | + |
| 13 | +## @CustomCodingKey\(String) |
| 14 | + |
| 15 | +Use a custom String value for a Property's CodingKey |
| 16 | + |
| 17 | +```swift |
| 18 | +@CustomCodable |
| 19 | +struct YourType: Codable { |
| 20 | + @CodingKey("your-Custom_naming") |
| 21 | + let firstProperty: String // Coding key will be "your-Custom_naming" |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +## CodingKeyPrefix\(String) |
| 26 | + |
| 27 | +Set a property's CodingKey with a custom value |
| 28 | + |
| 29 | +```swift |
| 30 | +@CustomCodable |
| 31 | +struct YourType: Codable { |
| 32 | + @CodingKeyPrefix("beta-") |
| 33 | + let firstProperty: String // CodingKey will be "beta-firstProperty" |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +```swift |
| 38 | +@CustomCodable @CodingKeyPrefix("beta-") |
| 39 | +struct YourType: Codable { |
| 40 | + let firstProperty: String // CodingKey will be "beta-firstProperty" |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +## CodingKeySuffix\(String) |
| 45 | + |
| 46 | +/// Add a Suffix a property's CodingKey or Type's CodingKeys with a custom value |
| 47 | + |
| 48 | +```swift |
| 49 | +@CustomCodable |
| 50 | +struct YourType: Codable { |
| 51 | + @CodingKeySuffix("-beta") |
| 52 | + let firstProperty: String // CodingKey will be "firstProperty-beta" |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +```swift |
| 57 | +@CustomCodable @CodingKeySuffix("-beta") |
| 58 | +struct YourType: Codable { |
| 59 | + let firstProperty: String // CodingKey will be "firstProperty-beta" |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +## CamelCase |
| 64 | + |
| 65 | +/// Make the CodingKey for a property or Type `camelCase` |
| 66 | + |
| 67 | +```swift |
| 68 | +@CustomCodable |
| 69 | +struct YourType: Codable { |
| 70 | + @CamelCase |
| 71 | + let first-property: String // CodingKey will be "firstProperty" |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +```swift |
| 76 | +@CustomCodable @CamelCase |
| 77 | +struct YourType: Codable { |
| 78 | + let first-property: String // CodingKey will be "firstProperty" |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +## @FlatCase |
| 83 | + |
| 84 | +Make the CodingKey for a property or Type `flatcase` |
| 85 | + |
| 86 | +```swift |
| 87 | +@CustomCodable |
| 88 | +struct YourType: Codable { |
| 89 | + @FlatCase |
| 90 | + let firstProperty: String // CodingKey will be "firstproperty" |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +```swift |
| 95 | +@CustomCodable @FlatCase |
| 96 | +struct YourType: Codable { |
| 97 | + let firstProperty: String // CodingKey will be "firstproperty" |
| 98 | +} |
| 99 | +``` |
| 100 | + |
| 101 | +## @PascalCase |
| 102 | + |
| 103 | +Make the CodingKey for a property or Type `PascalCase` |
| 104 | + |
| 105 | +```swift |
| 106 | +@CustomCodable |
| 107 | +struct YourType: Codable { |
| 108 | + @PascalCase |
| 109 | + let firstProperty: String // CodingKey will be "FirstProperty" |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +```swift |
| 114 | +@CustomCodable @PascalCase |
| 115 | +struct YourType: Codable { |
| 116 | + let firstProperty: String // CodingKey will be "FirstProperty" |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +## @UpperCase |
| 121 | + |
| 122 | +Make the CodingKey for a property or Type `UPPERCASE` |
| 123 | + |
| 124 | +```swift |
| 125 | +@CustomCodable |
| 126 | +struct YourType: Codable { |
| 127 | + @UpperCase |
| 128 | + let firstProperty: String // CodingKey will be "FIRSTPROPERTY" |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +```swift |
| 133 | +@CustomCodable @UpperCase |
| 134 | +struct YourType: Codable { |
| 135 | + let firstProperty: String // CodingKey will be "FIRSTPROPERTY" |
| 136 | +} |
| 137 | +``` |
| 138 | + |
| 139 | +## @SnakeCase |
| 140 | + |
| 141 | +Make the CodingKey for a property or Type `snake_case` |
| 142 | + |
| 143 | +```swift |
| 144 | +@CustomCodable |
| 145 | +struct YourType: Codable { |
| 146 | + @SnakeCase |
| 147 | + let firstProperty: String // CodingKey will be "first_property" |
| 148 | +} |
| 149 | +``` |
| 150 | + |
| 151 | +```swift |
| 152 | +@CustomCodable @SnakeCase |
| 153 | +struct YourType: Codable { |
| 154 | + let firstProperty: String // CodingKey will be "first_property" |
| 155 | +} |
| 156 | +``` |
| 157 | + |
| 158 | +## @CamelSnakeCase |
| 159 | + |
| 160 | +Make the CodingKey for a property or Type `camel_Snake_Case` |
| 161 | + |
| 162 | +```swift |
| 163 | +@CustomCodable |
| 164 | +struct YourType: Codable { |
| 165 | + @CamelSnakeCase |
| 166 | + let firstProperty: String // CodingKey will be "first_Property" |
| 167 | +} |
| 168 | +``` |
| 169 | + |
| 170 | +```swift |
| 171 | +@CustomCodable @CamelSnakeCase |
| 172 | +struct YourType: Codable { |
| 173 | + let firstProperty: String // CodingKey will be "first_Property" |
| 174 | +} |
| 175 | +``` |
| 176 | + |
| 177 | +## @PascalSnakeCase |
| 178 | + |
| 179 | +Make the CodingKey for a property or Type `Pascal_Snake_Case` |
| 180 | + |
| 181 | +```swift |
| 182 | +@CustomCodable |
| 183 | +struct YourType: Codable { |
| 184 | + @PascalSnakeCase |
| 185 | + let firstProperty: String // CodingKey will be "First_Property" |
| 186 | +} |
| 187 | +``` |
| 188 | + |
| 189 | +```swift |
| 190 | +@CustomCodable @PascalSnakeCase |
| 191 | +struct YourType: Codable { |
| 192 | + let firstProperty: String // CodingKey will be "First_Property" |
| 193 | +} |
| 194 | +``` |
| 195 | + |
| 196 | +## @ScreamingSnakeCase |
| 197 | + |
| 198 | +Make the CodingKey for a property or Type `SCREAMING_SNAKE_CASE` |
| 199 | + |
| 200 | +```swift |
| 201 | +@CustomCodable |
| 202 | +struct YourType: Codable { |
| 203 | + @ScreamingSnakeCase |
| 204 | + let firstProperty: String // CodingKey will be "FIRST_PROPERTY" |
| 205 | +} |
| 206 | +``` |
| 207 | + |
| 208 | +```swift |
| 209 | +@CustomCodable @ScreamingSnakeCase |
| 210 | +struct YourType: Codable { |
| 211 | + let firstProperty: String // CodingKey will be "FIRST_PROPERTY" |
| 212 | +} |
| 213 | +``` |
| 214 | + |
| 215 | +## @KebabCase |
| 216 | + |
| 217 | +Make the CodingKey for a property or Type `kebab-case` |
| 218 | + |
| 219 | +```swift |
| 220 | +@CustomCodable |
| 221 | +struct YourType: Codable { |
| 222 | + @KebabCase |
| 223 | + let firstProperty: String // CodingKey will be "first-property" |
| 224 | +} |
| 225 | +``` |
| 226 | + |
| 227 | +```swift |
| 228 | +@CustomCodable @KebabCase |
| 229 | +struct YourType: Codable { |
| 230 | + let firstProperty: String // CodingKey will be "first-property" |
| 231 | +} |
| 232 | +``` |
| 233 | + |
| 234 | +## @CamelKebabCase |
| 235 | + |
| 236 | +Make the CodingKey for a property or Type `camel-Kebab-Case` |
| 237 | + |
| 238 | +```swift |
| 239 | +@CustomCodable |
| 240 | +struct YourType: Codable { |
| 241 | + @CamelKebabCase |
| 242 | + let firstProperty: String // CodingKey will be "first-Property" |
| 243 | +} |
| 244 | +``` |
| 245 | + |
| 246 | +```swift |
| 247 | +@CustomCodable @CamelKebabCase |
| 248 | +struct YourType: Codable { |
| 249 | + let firstProperty: String // CodingKey will be "first-Property" |
| 250 | +} |
| 251 | +``` |
| 252 | + |
| 253 | +## @PascalKebabCase |
| 254 | + |
| 255 | +Make the CodingKey for a property or Type `Pascal-Kebab-Case` |
| 256 | + |
| 257 | +```swift |
| 258 | +@CustomCodable |
| 259 | +struct YourType: Codable { |
| 260 | + @PascalKebabCase |
| 261 | + let firstProperty: String // CodingKey will be "First-Property" |
| 262 | +} |
| 263 | +``` |
| 264 | + |
| 265 | +```swift |
| 266 | +@CustomCodable @PascalKebabCase |
| 267 | +struct YourType: Codable { |
| 268 | + let firstProperty: String // CodingKey will be "First-Property" |
| 269 | +} |
| 270 | +``` |
| 271 | + |
| 272 | +## @ScreamingKebabCase |
| 273 | + |
| 274 | +Make the CodingKey for a property or Type `SCREAMING-KEBAB-CASE` |
| 275 | + |
| 276 | +```swift |
| 277 | +@CustomCodable |
| 278 | +struct YourType: Codable { |
| 279 | + @ScreamingKebabCase |
| 280 | + let firstProperty: String // CodingKey will be "FIRST-PROPERTY" |
| 281 | +} |
| 282 | +``` |
| 283 | + |
| 284 | +```swift |
| 285 | +@CustomCodable @ScreamingKebabCase |
| 286 | +struct YourType: Codable { |
| 287 | + let firstProperty: String // CodingKey will be "FIRST-PROPERTY" |
| 288 | +} |
| 289 | +``` |
| 290 | +</details> |
0 commit comments