From 27b655efa4e797a7d36dc8d84a59fdedc022826b Mon Sep 17 00:00:00 2001 From: Mccc <> Date: Thu, 21 Nov 2024 18:36:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example/SmartCodable/AppDelegate.swift | 4 +- Example/SmartCodable/TestViewController.swift | 7 +- README.md | 74 ++++++++++++++----- .../Classes/Sentinel/SmartSentinel.swift | 3 + 4 files changed, 62 insertions(+), 26 deletions(-) diff --git a/Example/SmartCodable/AppDelegate.swift b/Example/SmartCodable/AppDelegate.swift index 41116c2..6c6987d 100644 --- a/Example/SmartCodable/AppDelegate.swift +++ b/Example/SmartCodable/AppDelegate.swift @@ -19,7 +19,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { SmartSentinel.debugMode = .verbose SmartSentinel.onLogGenerated { logs in - +// print(logs) + // 解析的日志, 可以用来上传服务器 } @@ -47,3 +48,4 @@ extension AppDelegate { window?.makeKeyAndVisible() } } + diff --git a/Example/SmartCodable/TestViewController.swift b/Example/SmartCodable/TestViewController.swift index 66135ee..2aa8296 100644 --- a/Example/SmartCodable/TestViewController.swift +++ b/Example/SmartCodable/TestViewController.swift @@ -70,26 +70,23 @@ class TestViewController: BaseViewController { // let model = Model.deserialize(from: dict) - let model = [Model].deserialize(from: [dict, dict1]) + let model = [SomeModel].deserialize(from: [dict, dict1]) } - struct Model: SmartCodable { + struct SomeModel: SmartCodable { var sub: SubModel = SubModel() var sub2s: [SubTwoModel] = [] - var a: Int = 0 var b: Int = 0 var c: Int = 0 } - struct SubModel: SmartCodable { var sub_a: Int = 0 var sub_b: Int = 0 var sub_c: Int = 0 } - struct SubTwoModel: SmartCodable { var sub2_a: Int = 0 var sub2_b: Int = 0 diff --git a/README.md b/README.md index 3e36ea5..e3cbf4d 100644 --- a/README.md +++ b/README.md @@ -139,32 +139,66 @@ If you don't know how to use it, check it out. -## Debug log +## **Sentinel** 哨兵模式 -**SmartSentinel Error** indicates that **SmartCodable** encountered a resolution problem and executed compatibility logic. This does not mean that the analysis failed. +SmartCodable内部集成了**Smart Sentinel**,它可以监听整个解析过程。当解析结束之后,输出格式化的日志信息。 -SmartCodable encourages the root of the resolution problem: it does not require SmartCodable compatibility logic. +该信息仅作辅助信息,帮助发现并排查问题。并不代表本次解析失败。 -出现 **SmartSentinel Error** 日志代表着 **SmartCodable** 遇到了解析问题,执行了兼容逻辑。 并不代表着本次解析失败。 +``` +================================ [Smart Sentinel] ================================ +Array 👈🏻 👀 + ╆━ Index 0 + ┆┄ a: Expected to decode 'Int' but found ‘String’ instead. + ┆┄ b: Expected to decode 'Int' but found ’Array‘ instead. + ┆┄ c: No value associated with key. + ╆━ sub: SubModel + ┆┄ sub_a: No value associated with key. + ┆┄ sub_b: No value associated with key. + ┆┄ sub_c: No value associated with key. + ╆━ sub2s: [SubTwoModel] + ╆━ Index 0 + ┆┄ sub2_a: No value associated with key. + ┆┄ sub2_b: No value associated with key. + ┆┄ sub2_c: No value associated with key. + ╆━ Index 1 + ┆┄ sub2_a: Expected to decode 'Int' but found ’Array‘ instead. + ╆━ Index 1 + ┆┄ a: No value associated with key. + ┆┄ b: Expected to decode 'Int' but found ‘String’ instead. + ┆┄ c: Expected to decode 'Int' but found ’Array‘ instead. + ╆━ sub: SubModel + ┆┄ sub_a: Expected to decode 'Int' but found ‘String’ instead. + ╆━ sub2s: [SubTwoModel] + ╆━ Index 0 + ┆┄ sub2_a: Expected to decode 'Int' but found ‘String’ instead. + ╆━ Index 1 + ┆┄ sub2_a: Expected to decode 'Int' but found 'null' instead. +==================================================================================== +``` + + + +如果你要使用它,请开启它: -SmartCodable鼓励从根本上解决解析中的问题,即:不需要用到SmartCodable的兼容逻辑。 +``` +SmartSentinel.debugMode = .verbose + +public enum Level: Int { + /// 不记录日志 + case none + /// 详细的日志 + case verbose + /// 警告日志:仅仅包含类型不匹配的情况 + case alert +} +``` + +如果你想获取这个日志用来上传服务器: ``` - ======================== [Smart Decoding Log] ======================== - Family 👈🏻 👀 - |- name : Expected to decode String but found an array instead. - |- location: Expected to decode String but found an array instead. - |- date : Expected to decode Date but found an array instead. - |> father: Father - |- name: Expected String value but found null instead. - |- age : Expected to decode Int but found a string/data instead. - |> dog: Dog - |- hobby: Expected to decode String but found a number instead. - |> sons: [Son] - |- [Index 0] hobby: Expected to decode String but found a number instead. - |- [Index 0] age : Expected to decode Int but found a string/data instead. - |- [Index 1] age : Expected to decode Int but found an array instead. - ========================================================================= +SmartSentinel.onLogGenerated { logs in +} ``` diff --git a/SmartCodable/Classes/Sentinel/SmartSentinel.swift b/SmartCodable/Classes/Sentinel/SmartSentinel.swift index 0b94cb5..08fa931 100644 --- a/SmartCodable/Classes/Sentinel/SmartSentinel.swift +++ b/SmartCodable/Classes/Sentinel/SmartSentinel.swift @@ -148,8 +148,11 @@ extension SmartSentinel { extension SmartSentinel { public enum Level: Int { + /// 不记录日志 case none + /// 详细的日志 case verbose + /// 警告日志:仅仅包含类型不匹配的情况 case alert }