在Swift 4.2中如何使数据类型通用

时间:2019-03-07 07:56:22

标签: arrays swift generics

struct BaseResponse<T:Decodable>: Decodable {
    var code : Int
    var status : String
    var message : String
    var data : T?
}

这是我的基本回答课。

一些时间响应来自具有多个对象的数组,而一些时间来自“数据”键中的字典。

我想使数据键动态地接受当前只接受字典的数组和字典。

可以动态化吗?

1 个答案:

答案 0 :(得分:0)

struct BaseResponse<T:Decodable>: Decodable {
    var code : Int
    var status : String
    var message : String
    var data : T?
    var datas: [T]?
}

我的项目 enter image description here