This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HTTP通信用ライブラリ | |
github "Alamofire/Alamofire" | |
# RxSwift | |
github "ReactiveX/RxSwift" | |
# JSON parser | |
github "ikesyo/Himotoki" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Alamofire | |
import RxSwift | |
/** | |
API通信をするためのプロトコル | |
- parameters: パラメーターを指定 | |
- baseURL: APIのドメインを指定 | |
- path: APIのパスを指定 | |
- method: CRUDを指定 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EventsRequest | |
.GetEvents(count) | |
.request() | |
.subscribe( | |
onNext: { | |
print("API response: \($0)") | |
}, onError: { | |
print("Error: \($0)") | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import RxSwift | |
import RxCocoa | |
/** | |
Event一覧を表示するViewController | |
*/ | |
class EventsViewController: UIViewController { | |
private let viewModel = EventsViewModel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RxSwift | |
import RxCocoa | |
/** | |
RxSwiftで同期・非同期・並列処理をするためのシングルトン | |
- main: 同期処理 | |
- serialBackground: 非同期処理 | |
- concurrentBackground: 並列処理 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Started ---- | |
Subscribed | |
Subscribed | |
First 0 | |
Second 0 | |
First 1 | |
Second 1 | |
First 2 | |
Second 2 | |
First 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 秒数カウンターを実装。いまは実装内容を深く考えないでください。 | |
func myInterval(interval: NSTimeInterval) -> Observable<Int> { | |
return Observable.create { observer in | |
print("Subscribed") | |
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) | |
let timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue) | |
var next = 0 | |
dispatch_source_set_timer(timer, 0, UInt64(interval * Double(NSEC_PER_SEC)), 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Viewの状態を扱うenum | |
- .Working: 描画する要素があり、アプリが正常に動いている状態 | |
- .Blank: 描画する要素がない状態 | |
- .Requesting: 描画する要素を読み込んでいる状態 | |
- .Error(ErrorType): エラーが起きている状態 | |
*/ | |
enum ViewState { | |
case Working | |
case Blank |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RxSwift | |
import UIKit | |
/** | |
EventsViewControllerの状態を扱うViewModel | |
- eventModel: Eventに関するデータを扱うモデル | |
- scheduler: RxSwiftで非同期通信を行うためのシングルトン | |
- disposeBag: RxSwiftで不要なstreamを削除するためのクラス | |
- events: Event一覧を格納 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Himotoki | |
/** | |
Event一覧を取得した後のJSONエンコードを設定 | |
*/ | |
struct EventListResponse: Decodable { | |
internal let results_returned: Int | |
internal let results_start: String | |
internal let events: [Events] |
OlderNewer