一个人为的解决方案,也就是展示一般方法并且更易于理解的内容如下:
import UIKit import RxSwift import RxCocoa struct Item { let identification: String let content: String } struct ItemsManager { let items: Variable<[Item]> = Variable<[Item]>( [Item(identification: "some id1", content: "some content"), Item(identification: "some id2", content: "some more content")] ) } struct ItemsViewModel { let itemsManager = ItemsManager() let myItems:Observable<[String]> init() { myItems = itemsManager.items .map({ someArrayOfItems in return someArrayOfItems.map {$0.content } }) } } class ItemListViewController: UIViewController { @IBOutlet weak var tableView: UITableView! let itemsViewModel = ItemsViewModel() let disposeBag = DisposeBag() override func viewDidLoad() { super.viewDidLoad() itemsViewModel.myItems .bindTo(tableView.rx_itemsWithCellIdentifier("itemListCell")) { (row, element, cell) in guard let myCell: UITableViewCell = cell else { return } myCell.textLabel?.text = element } .addDisposableTo(disposeBag) } }