1、pod 引入所需的库
pod 'Cartography' # swift 布局
pod 'RxSwift'
pod 'RxCocoa'
pod 'HandyJSON', '5.0.0-beta'
升级xcode到10.2之后,swift编译版本为5.0。
在引入HandyJSON 的时候,默认是4.2.1版本,报错了:Undefined symbols for architecture x86_64:
“_swift_getFieldAt”。解决办法是使用5.0.0-beta版本就可以了。
2、新建viewcontroller、viewmodel和model,代码如下:
view controller: 里边新建一个tableview,然后和viewmodel的dataSourceObservable和tableview绑定。
import UIKit
import Cartography
class MVVMViewController: UIViewController {
let viewModel = MVVMViewModel() // view 层持有 viewModel
let tableView = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "天行数据"
view.addSubview(tableView)
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 112
tableView.register(MVVMTableView