12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- //
- // TSBaseModel.swift
- // TSLiveWallpaper
- //
- // Created by 100Years on 2024/12/22.
- //
- import ObjectMapper
- open class TSBaseModel: NSObject, Mappable, NSCopying {
- public static func model(data: Data) -> TSBaseModel? {
- do {
- let object = try JSONSerialization.jsonObject(with: data)
- if let dict = object as? [String: AnyHashable] {
- return Self.init(json: dict)
- }
- } catch _ {
- return nil
- }
- return nil
- }
-
- open var data: Data? {
- let json = toJSON()
- do {
- let data = try JSONSerialization.data(withJSONObject: json)
- return data
- } catch _ {
- return nil
- }
- }
-
- required convenience public init?(map: ObjectMapper.Map) {
- self.init()
- mapping(map: map)
- }
-
- required convenience public init?(json: [String: Any]) {
- self.init(JSON: json)
- }
-
- open func mapping(map: ObjectMapper.Map) {}
-
- open func copy(with zone: NSZone? = nil) -> Any {
- let json = toJSON()
- return Self.init(JSON: json) ?? Self.init(JSON: [:])!
- }
-
- // deinit {
- // debugPrint("♻️♻️♻️ TGRootViewController -> \(type(of: self)) deinit ♻️♻️♻️")
- // }
- }
|