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

How to use Generic,like HandyJSON? #1149

Open
zhaoxianxin opened this issue May 15, 2024 · 0 comments
Open

How to use Generic,like HandyJSON? #1149

zhaoxianxin opened this issue May 15, 2024 · 0 comments

Comments

@zhaoxianxin
Copy link

zhaoxianxin commented May 15, 2024

struct DSBaseResponse: Mappable {
init?(map: Map) {
}

var code = 0
private var msg: String?
var data: T?
/// 适配没有套到data层中
var total = 0
var rows: T?

mutating func mapping(map: Map) {
    msg <- map["message"]
    total <- map["total"]
    code <- map["code"]
    rows <- map["rows"]
    data <- map["data"]
}

}

T maybe is Any,[T], [String, Any],Int ... I cannot let T must confirm protocol Mappable, such as :

struct DSBaseResponse<T: Mappable>: Mappable {
}

how can I design this struct? like HandyJSON, HandyJSON can use like this.

// test
let res = .... network response string
let result = DSBaseResponse(JSONString: res.string)

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

No branches or pull requests

1 participant