RxPagination

所属分类:collect
开发工具:Swift
文件大小:0KB
下载次数:0
上传日期:2017-10-12 16:39:58
上 传 者sh-1993
说明:  “网络中面向协议编程”的演示项目。,
(The demo project for "Protocol-Oriented Programming in Networking".,)

文件列表:
Cartfile (180, 2017-07-26)
Cartfile.resolved (252, 2017-07-26)
LICENSE (1077, 2017-07-26)
Pagination.xcodeproj/ (0, 2017-07-26)
Pagination.xcodeproj/project.pbxproj (36191, 2017-07-26)
Pagination.xcodeproj/project.xcworkspace/ (0, 2017-07-26)
Pagination.xcodeproj/project.xcworkspace/contents.xcworkspacedata (135, 2017-07-26)
Pagination/ (0, 2017-07-26)
Pagination/AppDelegate.swift (290, 2017-07-26)
Pagination/Assets.xcassets/ (0, 2017-07-26)
Pagination/Assets.xcassets/AppIcon.appiconset/ (0, 2017-07-26)
Pagination/Assets.xcassets/AppIcon.appiconset/Contents.json (1077, 2017-07-26)
Pagination/Base.lproj/ (0, 2017-07-26)
Pagination/Base.lproj/LaunchScreen.storyboard (1663, 2017-07-26)
Pagination/Base.lproj/Main.storyboard (7948, 2017-07-26)
Pagination/DisposeBag+Bulk.swift (148, 2017-07-26)
Pagination/GitHubAPI.swift (657, 2017-07-26)
Pagination/GitHubRequest.swift (403, 2017-07-26)
Pagination/Info.plist (1495, 2017-07-26)
Pagination/PaginationRequest.swift (772, 2017-07-26)
Pagination/PaginationResponse.swift (170, 2017-07-26)
Pagination/PaginationResponseType.swift (761, 2017-07-26)
Pagination/PaginationViewModel.swift (1895, 2017-07-26)
Pagination/Repository.swift (388, 2017-07-26)
Pagination/RepositoryCell.swift (232, 2017-07-26)
Pagination/SearchRepositoriesViewController.swift (921, 2017-07-26)
Pagination/Session+Rx.swift (717, 2017-07-26)
Pagination/UIScrollView+Rx.swift (792, 2017-07-26)
Pagination/UITableView+Rx.swift (638, 2017-07-26)
Pagination/UIViewController+Rx.swift (792, 2017-07-26)
Tests/ (0, 2017-07-26)
Tests/Fixture.swift (669, 2017-07-26)
Tests/Info.plist (733, 2017-07-26)
Tests/PaginationViewModelTests.swift (2184, 2017-07-26)
Tests/SearchRepositories.json (160731, 2017-07-26)
Tests/TestSessionAdapter.swift (1094, 2017-07-26)
screenshot.png (114259, 2017-07-26)

# RxPagination This is the demo project for my presentation at try! Swift conference 2016. - Slides: https://speakerdeck.com/ishkawa/protocol-oriented-programming-in-networking - Video: https://news.realm.io/news/tryswift-yosuke-ishikawa-protocol-oriented-networking/ ## Set Up - `carthage bootstrap --platform iOS` ## Requirements - Swift 3.0.1 - Xcode 8.1 ## Summary This demo project illustrates how to use RxSwift, Action and APIKit. The demo app fetches repositories via GitHub search API and displays them using the libraries. ### ViewModel `PaginationViewModel` is a view model for pagination. It has an initializer with type parameter `Request`, which is constrained to conform to `PaginationRequest` protocol. When `PaginationViewModel` is instantiated via `init(baseRequest:)`, the type of its property that represents pagination elements will be inferred as `Observable<[Request.Response.Element]>`. ```swift class PaginationViewModel { let indicatorViewAnimating: Driver let elements: Driver<[Element]> let loadError: Driver init( baseRequest: Request, viewWillAppear: Driver, scrollViewDidReachBottom: Driver) where Request.Response.Element == Element {...} } ``` ### ViewController Once ViewModel is instantiated with a `Request` type parameter, remained task that ViewController have to do is binding input streams and output streams. ```swift class SearchRepositoriesViewController: UITableViewController { @IBOutlet weak var indicatorView: UIActivityIndicatorView! private let disposeBag = DisposeBag() private var viewModel: PaginationViewModel! override func viewDidLoad() { super.viewDidLoad() let baseRequest = GitHubAPI.SearchRepositoriesRequest(query: "Swift") viewModel = PaginationViewModel( baseRequest: baseRequest, viewWillAppear: rx.viewWillAppear.asDriver(), scrollViewDidReachBottom: tableView.rx.reachedBottom.asDriver()) disposeBag.insert([ viewModel.indicatorViewAnimating.drive(indicatorView.rx.isAnimating), viewModel.elements.drive(tableView.rx.items(cellIdentifier: "Cell", cellType: RepositoryCell.self)), viewModel.loadError.drive(onNext: { print($0) }), ]) } } ``` ## Contact Twitter: https://twitter.com/_ishkawa

近期下载者

相关文件


收藏者