使用 Swift 創(chuàng)建 Model 類時(shí)铁追,model 類屬性變量前需加 @objc 祸穷,否則 YYModel 將不能讀取 model 類屬性變量蜻势,即無(wú)法解析返回空等限。
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)
}
}
}