- 実践 iOSアプリ開発 - ReactorKitを利用した設計手法 速習会@Wantedly
- 題材アプリ
- GitHub のリポジトリの検索と閲覧
- https://github.com/hedjirog/GitHubSearch
- 題材アプリをビルド & 実行
git clone -b workshop https://github.com/hedjirog/GitHubSearch.git
cd GitHubSearch
open GitHubSearch.xcworkspace- GitHub の Personal access token を発行
curlコマンドで rate_limit を確認ができる
curl -H "Authorization: token **************" https://api.github.com/rate_limit- 発行した access token を利用するようにコードを書き変え
AppDelegate内のaccessToken変数の値を変更
diff --git a/GitHubSearch/AppDelegate.swift b/GitHubSearch/AppDelegate.swift
index 6fe7bde..8a9859b 100644
--- a/GitHubSearch/AppDelegate.swift
+++ b/GitHubSearch/AppDelegate.swift
@@ -1,7 +1,7 @@
import UIKit
struct Const {
- static let accessToken = ""
+ static let accessToken = "**************"
}検索結果がない場合にUITableViewを非表示にする
💡 ヒント:
- UITableView の背後に空の際に表示する UILabel が存在する
- View である
SearchViewControllerのbindメソッドを変更するreactor.stateのストリームを加工して、UITableView のisHiddenプロパティにバインディングする
検索回数の上限に達したらUIAlertControllerを表示する
💡 ヒント:
- View である
SearchViewControllerのbindメソッドを変更するreactor.stateのストリームを加工して、subscribe するshowAlertメソッドが適切に呼ばれるようにする
- Reactor である
SearchViewReactorのsetSearchedRepositoriesメソッドを変更する- エラー時に
Mutation.setLimitExceededを伝搬させる
- エラー時に
ページングを可能にする
💡 ヒント:
- Reactor である
SearchViewReactorのmutateメソッドを変更する- 頻繁に Action が伝搬してくるので、特定の条件でのみ Mutation を伝搬するようにする
- 条件:次のページを把握している、ローディング中でない、検索回数の上限に達していない
- 頻繁に Action が伝搬してくるので、特定の条件でのみ Mutation を伝搬するようにする
appendRepositoriesの Mutation を追加する
クエリの入力でのActionが伝搬することを確かめる
💡 ヒント:
SearchViewControllerSpecを変更する- UISearchBar のデリゲートメソッドを実行する
クエリ入力によるActionの伝搬によって変化したStateが伝搬することを確かめる
💡 ヒント:
SearchViewReactorSpecを変更する- スタブ化した
repositoryServiceのsearchRepositoriesメソッドの挙動を変更する - Reactor に Action を伝搬させる
ページングによるActionの伝搬によって変化したStateが伝搬することを確かめる