-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
model中的属性为可选类型的时候,JSON数据没有对应的字段,最后从model中取属性没有默认值 #20
Comments
可选属性的默认值是nil,想要默认值请使用非可选类型 |
如果属性使用可选类型,类型不匹配的时候该属性的结果也是nil。感觉如果使用Clean JSON得尽量使用不可选类型。 |
嗯嗯,尽量使用不可选类型。除非你真的需要判断是否为nil |
项目中之前用的是Codable Wrapper,现在准备用你的Clean Json,感觉使用更简单,对源码侵入也少,👍 |
感谢使用,有问题可以反馈给我 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
struct CleanJSONModel: Codable {
var name: String?
}
if model.name == nil {
debugPrint("没有name")
}
The text was updated successfully, but these errors were encountered: