第四天 rxcocoa

HackerNewsReaderDemo

 

        HackerNewsAPI.sharedApi.newStories()
            .observeOn(ConcurrentDispatchQueueScheduler.init(globalConcurrentQueueQOS: .Background))
            .map { $0.dropLast($0.count - 15).map { HackerNewsAPI.sharedApi.item($0) } }
            .map { $0.zip({ $0 }) }
            .switchLatest()
            .map { $0.map { ItemViewModel(item: $0) } }
            .observeOn(MainScheduler.instance)
            .doOnNext { [unowned self] _ in
                self.endUpdateTableView()
            }
            .doOnError { [unowned self] _ in
                self.endUpdateTableView()
            }
            .bindTo(tableView.rx_itemsWithCellIdentifier("ItemTableViewCell", cellType: ItemTableViewCell.self)) { (row, item, cell) in
                cell.viewModel = item
            }.addDisposableTo(disposeBag)

 

posted @ 2016-10-04 18:29  lianhuaren  阅读(184)  评论(0编辑  收藏  举报