From b69194cea1bad2895dbed5a967fab29519b229ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=CC=81ng?= Date: Tue, 6 Aug 2024 12:03:31 +0800 Subject: [PATCH 1/7] opt: test and docs --- README.md | 19 +++++++------- Tests/ExCodableTests/ExCodableTests.swift | 30 +++++++++++------------ 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 5618f9e..b87a716 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ struct TestStructWithEnum: ExAutoCodable { ```swift struct TestManualEncodeDecode: ExAutoCodable { - @ExCodable("int", encode: { encoder, value in + @ExCodable(encode: { encoder, value in encoder["int"] = value <= 0 ? 0 : value }, decode: { decoder in if let int: Int = decoder["int"], int > 0 { @@ -235,10 +235,9 @@ Custom type conversions for specific properties: ```swift struct TestCustomEncodeDecode: ExAutoCodable { - @ExCodable("int", decode: { decoder in - if let string: String = decoder["string"], - let int = Int(string) { - return int + @ExCodable(decode: { decoder in + if let string: String = decoder["string"] { + return string.count } return 0 }) private(set) @@ -251,9 +250,9 @@ Custom type conversions for specific model: ```swift struct TestCustomTypeConverter: ExAutoCodable { - @ExCodable("doubleFromBool") private(set) + @ExCodable private(set) var doubleFromBool: Double? = nil - @ExCodable("floatFromBool") private(set) + @ExCodable private(set) var floatFromBool: Double? = nil } @@ -355,7 +354,7 @@ ExCodable also supports throw errors: ```swift struct TestNonnullAndThrows: ExAutoCodable { - @ExCodable("int", nonnull: true, throws: true) private(set) + @ExCodable(nonnull: true, throws: true) private(set) var int: Int! = 0 } @@ -394,9 +393,9 @@ class TestSubclass: TestClass { ```swift struct TestStruct: ExAutoCodable, Equatable { - @ExCodable("int") private(set) + @ExCodable private(set) var int: Int = 0 - @ExCodable("string") private(set) + @ExCodable private(set) var string: String? = nil } diff --git a/Tests/ExCodableTests/ExCodableTests.swift b/Tests/ExCodableTests/ExCodableTests.swift index bee26a4..0626569 100644 --- a/Tests/ExCodableTests/ExCodableTests.swift +++ b/Tests/ExCodableTests/ExCodableTests.swift @@ -11,6 +11,15 @@ import XCTest // @testable import ExCodable +// MARK: ExCodable + +struct TestExCodable: ExAutoCodable, Equatable { + @ExCodable private(set) + var int: Int = 0 + @ExCodable private(set) + var string: String? = nil +} + // MARK: auto codable struct TestAutoCodable: Codable, Equatable { @@ -96,7 +105,7 @@ enum TestEnum: Int, Codable { } struct TestStructWithEnum: ExAutoCodable, Equatable { - @ExCodable("enum") private(set) + @ExCodable private(set) var `enum` = TestEnum.zero } @@ -136,7 +145,7 @@ fileprivate func message(for int: Int) -> String { struct TestCustomEncodeDecode: ExAutoCodable, Equatable { - @ExCodable("int", encode: { encoder, value in + @ExCodable(encode: { encoder, value in encoder["int"] = value <= 0 ? 0 : value }, decode: { decoder in if let int: Int = decoder["int"], int > 0 { @@ -199,9 +208,9 @@ extension TestSubscript: Codable { // MARK: type-conversions struct TestTypeConversion: ExAutoCodable, Equatable { - @ExCodable("intFromString") private(set) + @ExCodable private(set) var intFromString: Int? = nil - @ExCodable("stringFromInt") private(set) + @ExCodable private(set) var stringFromInt: String??? = nil } @@ -263,9 +272,9 @@ extension TestTypeConversions: Encodable, Decodable { // MARK: custom type-conversions struct TestCustomTypeConverter: ExAutoCodable, Equatable { - @ExCodable("doubleFromBool") private(set) + @ExCodable private(set) var doubleFromBool: Double? = nil - @ExCodable("boolFromDouble") private(set) + @ExCodable private(set) var boolFromDouble: Bool? = nil } @@ -374,15 +383,6 @@ struct TestNonnullWithThrows: ExAutoCodable, Equatable { var testThrows: TestThrows! = nil } -// MARK: ExCodable - -struct TestExCodable: ExAutoCodable, Equatable { - @ExCodable("int") private(set) - var int: Int = 0 - @ExCodable("string") private(set) - var string: String? = nil -} - // MARK: - Tests final class ExCodableTests: XCTestCase { From ea4ef9fd16e7447b8be8d17e5ee1454ce75dc37e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=CC=81ng?= Date: Tue, 6 Aug 2024 13:13:15 +0800 Subject: [PATCH 2/7] opt: docs --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b87a716..8fe742f 100644 --- a/README.md +++ b/README.md @@ -407,6 +407,8 @@ let copy = try? dict.decoded() as TestStruct ``` +> See the tests for more examples. + ## Requirements - iOS 12.0+ | tvOS 12.0+ | macOS 11.0+ | watchOS 4.0+ @@ -433,7 +435,9 @@ pod 'ExCodable', '~> 1.0.0' ### 0.x to 1.x -Quickly, but **DEPRECATED**: +When you update to ExCodable 1.0. + +Step 1: Update your code to use the old API - **DEPRECATED** but quick. - Replace protocol `ExCodable` with `ExCodableDEPRECATED`. - Add `static` to func `decodeForTypeConversion(_:codingKey:as:)` of protocol `KeyedDecodingContainerCustomTypeConversion`. @@ -456,7 +460,7 @@ extension TestExCodable: ExCodableDEPRECATED { ``` -Upgrade, SUGGESTED: +Step 2: Upgrade your models to the new API one by one - SUGGESTED: - Replace `protocol` `ExCodable` with `ExAutoCodable`. - Remove initializer `init(from decoder: Decoder) throws`. From 0e298f108cfc5e51efe6884d0828ad4877e75a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=ADng?= Date: Wed, 7 Aug 2024 23:44:49 +0800 Subject: [PATCH 3/7] opt: docs --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8fe742f..89cea93 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,8 @@ struct TestExCodable: ExAutoCodable { ## Usage + + ### 1. ExCodable `ExCodable` requires declaring properties with `var` and provide default values. From 542456bb324247cff953ed34ad50e1a8f1ace266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=ADng?= Date: Thu, 5 Sep 2024 16:22:44 +0800 Subject: [PATCH 4/7] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 89cea93..a525867 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@
[![Build and Test](https://github.com/ExCodable/ExCodable/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/ExCodable/ExCodable/actions/workflows/build-and-test.yml) [![GitHub Releases (latest SemVer)](https://img.shields.io/github/v/release/ExCodable/ExCodable.svg?sort=semver)](https://github.com/ExCodable/ExCodable/releases) +[![GitHub stars](https://badgen.net/github/stars/ExCodable/ExCodable)](https://github.com/ExCodable/ExCodable/stargazers/) +
[![Deploy to CocoaPods](https://github.com/ExCodable/ExCodable/actions/workflows/deploy_to_cocoapods.yml/badge.svg)](https://github.com/ExCodable/ExCodable/actions/workflows/deploy_to_cocoapods.yml) [![Cocoapods](https://img.shields.io/cocoapods/v/ExCodable.svg)](https://cocoapods.org/pods/ExCodable)
From 601cdcbb94709fb59f9705bdb0d261a1715a9d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=ADng?= Date: Fri, 6 Sep 2024 21:13:44 +0800 Subject: [PATCH 5/7] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index a525867..79e9037 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,11 @@
[![Build and Test](https://github.com/ExCodable/ExCodable/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/ExCodable/ExCodable/actions/workflows/build-and-test.yml) [![GitHub Releases (latest SemVer)](https://img.shields.io/github/v/release/ExCodable/ExCodable.svg?sort=semver)](https://github.com/ExCodable/ExCodable/releases) -[![GitHub stars](https://badgen.net/github/stars/ExCodable/ExCodable)](https://github.com/ExCodable/ExCodable/stargazers/) -
[![Deploy to CocoaPods](https://github.com/ExCodable/ExCodable/actions/workflows/deploy_to_cocoapods.yml/badge.svg)](https://github.com/ExCodable/ExCodable/actions/workflows/deploy_to_cocoapods.yml) [![Cocoapods](https://img.shields.io/cocoapods/v/ExCodable.svg)](https://cocoapods.org/pods/ExCodable)
[![LICENSE](https://img.shields.io/github/license/ExCodable/ExCodable.svg)](https://github.com/ExCodable/ExCodable/blob/master/LICENSE) +[![GitHub stars](https://badgen.net/github/stars/ExCodable/ExCodable)](https://github.com/ExCodable/ExCodable/stargazers/) [![@minglq](https://img.shields.io/twitter/url?url=https%3A%2F%2Fgithub.com%2Fiwill%2FExCodable)](https://twitter.com/minglq) En | [中文](https://iwill.im/ExCodable/) From 7f31d9a4a80036343a694fb68db866ef32c91ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=ADng?= Date: Wed, 9 Oct 2024 19:35:06 +0800 Subject: [PATCH 6/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 79e9037..4cd0655 100644 --- a/README.md +++ b/README.md @@ -486,7 +486,7 @@ struct TestExCodable: ExAutoCodable { ## Stars - Star Chart + Star Chart Hope ExCodable will help you! [Make a star](https://github.com/ExCodable/ExCodable/#repository-container-header) ⭐️ 🤩 From f4686d1845ab6c2a8da1763e7c6fb0fa35e216a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=ADng?= Date: Thu, 26 Dec 2024 21:26:31 +0800 Subject: [PATCH 7/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4cd0655..2da0241 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ [![GitHub stars](https://badgen.net/github/stars/ExCodable/ExCodable)](https://github.com/ExCodable/ExCodable/stargazers/) [![@minglq](https://img.shields.io/twitter/url?url=https%3A%2F%2Fgithub.com%2Fiwill%2FExCodable)](https://twitter.com/minglq) -En | [中文](https://iwill.im/ExCodable/) +En | [中文](https://excodable.iwill.im/) ## What's New in ExCodable 1.0