Skip to content

Commit

Permalink
优化readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Mccc committed Nov 21, 2024
1 parent 78440b7 commit 27b655e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 26 deletions.
4 changes: 3 additions & 1 deletion Example/SmartCodable/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

SmartSentinel.debugMode = .verbose
SmartSentinel.onLogGenerated { logs in

// print(logs)
// 解析的日志, 可以用来上传服务器
}


Expand Down Expand Up @@ -47,3 +48,4 @@ extension AppDelegate {
window?.makeKeyAndVisible()
}
}

7 changes: 2 additions & 5 deletions Example/SmartCodable/TestViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 54 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<SomeModel> 👈🏻 👀
╆━ 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
}
```


Expand Down
3 changes: 3 additions & 0 deletions SmartCodable/Classes/Sentinel/SmartSentinel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ extension SmartSentinel {
extension SmartSentinel {

public enum Level: Int {
/// 不记录日志
case none
/// 详细的日志
case verbose
/// 警告日志:仅仅包含类型不匹配的情况
case alert
}

Expand Down

0 comments on commit 27b655e

Please sign in to comment.