Skip to content
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

可以给某个key,单独设置默认值么? #14

Open
Jaylin0920 opened this issue Mar 5, 2021 · 3 comments
Open

可以给某个key,单独设置默认值么? #14

Jaylin0920 opened this issue Mar 5, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@Jaylin0920
Copy link

struct CustomAdapterAAA: JSONAdapter {
public func adapt(_ decoder: CleanDecoder) throws -> String {
return "default string"
}
}
这个方法可以给这个decoder解析出来的所有string设置默认值,想问下,可以给key设置单独的默认值么,比如说一个model里有strA,想要默认值是“strA”
strB,想要默认值是“strB”
支持这样单独设置默认值么?

@Pircate Pircate added the enhancement New feature or request label Sep 22, 2021
@OneTaoist
Copy link

@Pircate 大佬,实际项目中确实有很多这样的需求,model模型中同类型(例如字符串类型)的字段,有多个。但是我们想对不同的字段,单独设置不同的默认值。麻烦看看,有什么巧妙的办法?

@OneTaoist
Copy link

我这边研究了一下,可以参考这个资料:
https://juejin.cn/post/6974762996077690910
对于我们开发人员来说,就是需要在使用上简单、代码量少。😄
@Pircate

@Pircate
Copy link
Owner

Pircate commented Sep 22, 2021

你可以配合这个属性包装器一起使用的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants