使用 Swift 创建 Model 类时,model 类属性变量前需加 @objc ,否则 YYModel 将不能读取 model 类属性变量,即无法解析返回空。
import UIKit
class WBStatus: NSObject {
//
@objc var id: Int64 = 0
@objc var text: String?
//
override var description: String {
return yy_modelDescription()
}
}
class WBStatusListViewModel {
//
lazy var statusList = [WBStatus]()
func loadStatus(completion: @escaping (Bool)->()) {
//
WBNetworkManager.shared.statusList { (list, isSuccess) in
guard let array = NSArray.yy_modelArray(with: WBStatus.self, json: list ?? []) as? [WBStatus] else {
completion(isSuccess)
return
}
self.statusList += array
completion(isSuccess)
}
}
}