Swift中可编码属性的iOS通用类型 [英] iOS Generic type for codable property in Swift

查看:77
本文介绍了Swift中可编码属性的iOS通用类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取用于解析JSON的结构的通用变量

I need to get a generic variable for a struct for parsing a JSON

,但是我得到的错误是
Type' BaseJsonModel'不符合协议'Codable

but there is an error that I am getting Type 'BaseJsonModel' does not conform to protocol 'Codable

以下是我的结构

  struct BaseJsonStruct<T>: Codable {
    let info: String
    let data: T
 }

错误:-类型'BaseJsonModel'不符合协议'Codable'

Error:- Type 'BaseJsonModel' does not conform to protocol 'Codable'

推荐答案

T 还必须符合 Codable

struct BaseJsonStruct<T : Codable> : Codable {
    let info: String
    let data: T
}

这篇关于Swift中可编码属性的iOS通用类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆