IOS_Boss/IOS_study/Model/DBUser.swift
2025-07-27 12:33:06 +08:00

91 lines
3.5 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// DBUser.swift
// IOS_study
//
// Created by CC-star on 2025/7/14.
//
import Foundation
struct DBUser: Codable, Identifiable {//
var id = UUID().uuidString//id
var nickName = ""//
var cName = ""//
var cLogoURLStr = ""//logo
var cImageURLStrs: [String] = []//
var cAboutUS = ""//
var cProvince = "重庆"//
var cCity = ""//
var cIsUploaded: Bool { !cName.isEmpty }//
var hasPLJobs = false//
var hasReviews = false//
enum CodingKeys: String,CodingKey {
case id
case nickName
case cName
case cLogoURLStr
case cImageURLStrs
case cAboutUS
case cProvince
case cCity
case hasPLJobs
case hasReviews
}
func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: .id)
try container.encode(self.nickName, forKey: .nickName)
try container.encode(self.cName, forKey: .cName)
try container.encode(self.cLogoURLStr, forKey: .cLogoURLStr)
try container.encode(self.cImageURLStrs, forKey: .cImageURLStrs)
try container.encode(self.cAboutUS, forKey: .cAboutUS)
try container.encode(self.cProvince, forKey: .cProvince)
try container.encode(self.cCity, forKey: .cCity)
try container.encode(self.hasPLJobs, forKey: .hasPLJobs)
try container.encode(self.hasReviews, forKey: .hasReviews)
}
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(String.self, forKey: .id)
self.nickName = try container.decodeIfPresent(String.self, forKey: .nickName) ?? ""
self.cName = try container.decodeIfPresent(String.self, forKey: .cName) ?? ""
self.cLogoURLStr = try container.decodeIfPresent(String.self, forKey: .cLogoURLStr) ?? ""
self.cImageURLStrs = try container.decodeIfPresent([String].self, forKey: .cImageURLStrs) ?? []
self.cAboutUS = try container.decodeIfPresent(String.self, forKey: .cAboutUS) ?? ""
self.cProvince = try container.decodeIfPresent(String.self, forKey: .cProvince) ?? "重庆"
self.cCity = try container.decodeIfPresent(String.self, forKey: .cCity) ?? ""
self.hasPLJobs = try container.decodeIfPresent(Bool.self, forKey: .hasPLJobs) ?? false
self.hasReviews = try container.decodeIfPresent(Bool.self, forKey: .hasReviews) ?? false
}
//initinit
init(id: String = UUID().uuidString, nickName: String = "", cName: String = "", cLogoURLStr: String = "", cImageURLStrs: [String] = [], cAboutUS: String = "", cProvince: String = "重庆", cCity: String = "", hasPLJobs: Bool = false, hasReviews: Bool = false) {
self.id = id
self.nickName = nickName
self.cName = cName
self.cLogoURLStr = cLogoURLStr
self.cImageURLStrs = cImageURLStrs
self.cAboutUS = cAboutUS
self.cProvince = cProvince
self.cCity = cCity
self.hasPLJobs = hasPLJobs
self.hasReviews = hasReviews
}
}
//struct Company: Codable {//
// var name = ""//
// var logoURLStr = ""//logo
// var imageURLStrs: [String] = []//
// var aboutUS = ""//
// var province = ""//
// var city = ""//
// var isUploaded: Bool { !name.isEmpty }//
//}