Skip to content

Commit 378811b

Browse files
committed
Swift 5.9 Macro Support link
1 parent 95927d2 commit 378811b

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323

2424
## [中文说明](./README-zhCN.md)
2525

26+
# Swift 5.9 Macro Support
27+
28+
Is **<mark>In development</mark>**, chek [swift5.9-macro branch](https://github.com/winddpan/CodableWrapper/tree/swift5.9-macro)
29+
2630
## About
31+
2732
* This project is use `PropertyWrapper` to improve your `Codable` use experience.
2833
* Simply based on `JSONEncoder` `JSONDecoder`.
2934
* Powerful and simplifily API than [BetterCodable](https://github.com/marksands/BetterCodable) or [CodableWrappers](https://github.com/GottaGetSwifty/CodableWrappers).
@@ -40,12 +45,15 @@
4045
## Installation
4146

4247
#### Cocoapods
48+
4349
``` pod 'CodableWrapper' ```
4450

4551
#### Swift Package Manager
52+
4653
``` https://github.com/winddpan/CodableWrapper ```
4754

4855
## Example
56+
4957
```Swift
5058
enum Animal: String, Codable {
5159
case dog
@@ -65,7 +73,7 @@ struct ExampleModel: Codable {
6573
@Codec var bool: Bool = false
6674

6775
@Codec var unImpl: String?
68-
76+
6977
@Codec var animal: Animal = .dog
7078
}
7179

@@ -138,11 +146,12 @@ struct DataModel: Codable {
138146
}
139147
```
140148

141-
142149
## Usage
143150

144151
#### DefaultValue
152+
145153
> DefaultValue should implement `Codable` protocol
154+
146155
```swift
147156
struct ExampleModel: Codable {
148157
@Codec var bool: Bool = false
@@ -155,6 +164,7 @@ XCTAssertEqual(model.bool, false)
155164
```
156165

157166
#### Auto snake camel convert
167+
158168
```swift
159169
struct ExampleModel: Codable {
160170
@Codec var snake_string: String = ""
@@ -168,9 +178,11 @@ XCTAssertEqual(model.snake_string, "snake")
168178
XCTAssertEqual(model.camelString, "camel")
169179
```
170180

171-
#### CodingKeys
181+
#### CodingKeys
182+
172183
> Decoding: try each CodingKey until succeed
173184
> Encoding: use first CodingKey as Dictionary key
185+
174186
```swift
175187
struct ExampleModel: Codable {
176188
@Codec("int_Val", "intVal")
@@ -190,10 +202,10 @@ let data = try JSONEncoder().encode(model)
190202
let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
191203
XCTAssertEqual(jsonObject["int_Val"] as? Int, 233)
192204
XCTAssertEqual(jsonObject["intOptional"] as? Int, 234)
193-
194205
```
195206

196207
#### Basic type bridging
208+
197209
```swift
198210
struct ExampleModel: Codable {
199211
@Codec var int: Int?
@@ -210,6 +222,7 @@ XCTAssertEqual(model.bool, true)
210222
```
211223

212224
#### Transformer
225+
213226
```swift
214227
struct User: Codable {
215228
@Codec(transformer: SecondDateTransform())

0 commit comments

Comments
 (0)