20:swift-内嵌类型:数据模型

 

正文

 

复制代码
/*内嵌类型: 定义数据模型
 
 1: 枚举通常用于实现特定类或结构体的功能。
    类似的,它也可以在更加复杂的类型环境中方便的定义通用类和结构体。
    为实现这种功能,Swift 允许你定义内嵌类型,借此在支持类型的定义中嵌套枚举、类、或结构体。
    若要在一种类型中嵌套另一种类型,在其支持类型的大括号内定义即可。可以根据需求多级嵌套数个类型。
 
 */
import UIKit

struct BDTGiftModel: Codable {
    var errno: String
    var errmsg: String
    
    // 重写解析方法
    init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        errmsg = try container.decode(String.self, forKey: .errmsg)
        // 兼容todoDaysCnt字段
        do {
            errno = try container.decodeIfPresent(String.self, forKey: .errno) ?? "0"
        } catch DecodingError.typeMismatch {
            if let errnoInt = try container.decodeIfPresent(Int.self, forKey: .errno) {
                errno = String(errnoInt)
            } else {
                errno = "0"
            }
        }
    }
   
    
}

class InsertType20VC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    


}
复制代码

 

posted on   风zk  阅读(31)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示