tryswift/RxPagination
소개
"Protocol-Oriented Programming in Networking"의 데모 프로젝트입니다.
시스템 및 인프라측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalRxPagination
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<Element> is a view model for pagination. It has an initializer with type parameter Request, which is constrained to conform to PaginationRequest protocol. When PaginationViewModel<Element> is instantiated via init<Request>(baseRequest:), the type of its property that represents pagination elements will be inferred as Observable<[Request.Response.Element]>.
class PaginationViewModel<Element: Decodable> {
let indicatorViewAnimating: Driver<Bool>
let elements: Driver<[Element]>
let loadError: Driver<Error>
init<Request: PaginationRequest>(
baseRequest: Request,
viewWillAppear: Driver<Void>,
scrollViewDidReachBottom: Driver<Void>) 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.
class SearchRepositoriesViewController: UITableViewController {
@IBOutlet weak var indicatorView: UIActivityIndicatorView!
private let disposeBag = DisposeBag()
private var viewModel: PaginationViewModel<Repository>!
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
관련 프로젝트 살펴보기
불러오는 중…