Day_Count_Memory_Days/anniversary_Project/Tool/AV_usermodel.swift
2024-07-15 11:52:15 +08:00

68 lines
1.8 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.

//
// AV_usermodel.swift
// anniversary_Project
//
// Created by 16 on 2024/4/11.
//
import Foundation
import UIKit
import WCDBSwift
//
let userModelTableName = "UserModel"
class UserModel: TableCodable {
/// id
var identifier: Int?
var uid: String = ""
var name: String = ""
// var introduce: String = ""
var date: String = ""
var imageBase64: String? // Base64
var notificationEnabled: Bool = false
var type:String = ""
enum CodingKeys: String, CodingTableKey {
typealias Root = UserModel
static let objectRelationalMapping = TableBinding(CodingKeys.self)
case identifier
case uid
case name
// case introduce
case date
case imageBase64 = "image" // Base64 imageBase64
case notificationEnabled
case type
// Column constraints for primary key, unique, not null, default value and so on. It is optional.
static var columnConstraintBindings: [UserModel.CodingKeys: ColumnConstraint]? {
return [
.identifier:ColumnConstraint()
]
}
}
// UIImage Base64 imageBase64
func setImage(image: UIImage) {
if let imageData = image.pngData() {
self.imageBase64 = imageData.base64EncodedString()
}
}
// imageBase64 Base64 UIImage
func getImage() -> UIImage? {
if let base64String = self.imageBase64,
let imageData = Data(base64Encoded: base64String),
let image = UIImage(data: imageData) {
return image
}
return nil
}
}