import SwiftUI import Foundation import ObjectMapper import Then import RxSwift import RxCocoa import HandyJSON
structIntroduction: Identifiable, Decodable, Mappable, HandyJSON{ init() { } init?(map: Map) { } var id =UUID() var idForDataBase: Int64=Int64() var image: String=String() var title: String=String() var text: String=String() //这里的date原是想要展示日期,现在就用于当备注 var date: String=String() init(idForDataBase: Int64, image: String, title: String, text: String, date: String) { self.idForDataBase = idForDataBase self.image = image self.title = title self.text = text self.date = date } mutatingfuncmapping(map: Map) { id <- map["id"] idForDataBase <- map["idForDataBase"] image <- map["image"] title <- map["title"] text <- map["text"] date <- map["date"] } }
//解析的话,只遵循HandyJSON协议即可,如下,这样就可以使用了:
1 2 3 4 5 6 7 8 9 10
import Foundation import HandyJSON
structIntroduction: HandyJSON{ var idForDataBase =Int64() var image: String=String() var title: String=String() var text: String=String() var date: String=String() }