Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,388 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,4 @@ fastlane/report.xml | |
fastlane/Preview.html | ||
fastlane/screenshots | ||
fastlane/test_output | ||
Pods |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use_frameworks! | ||
|
||
target 'RxSwiftiOS' do | ||
pod 'RxSwift', '3.1.0' | ||
pod 'RxCocoa', '3.1.0' | ||
pod 'Unbox', '2.3.0' | ||
pod 'RealmSwift', '2.2.0' | ||
pod 'RxRealm', '0.5.1' | ||
pod 'RxRealmDataSources', '0.2.1' | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
# RxSwiftoniOS | ||
Sample code from my dotSwift 2017 talk in Paris | ||
Sample code from my dotSwift 2017 talk in Paris. Clone and install CocoaPods, then run the app. |
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
RxSwiftiOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// AppDelegate.swift | ||
// RxSwiftiOS | ||
// | ||
// Created by Marin Todorov on 1/21/17. | ||
// Copyright © 2017 Underplot ltd. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
@UIApplicationMain | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
var window: UIWindow? | ||
} |
48 changes: 48 additions & 0 deletions
48
RxSwiftiOS/Assets.xcassets/AppIcon.appiconset/Contents.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "20x20", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "20x20", | ||
"scale" : "3x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "29x29", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "29x29", | ||
"scale" : "3x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "40x40", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "40x40", | ||
"scale" : "3x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "60x60", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"size" : "60x60", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--View Controller--> | ||
<scene sceneID="EHf-IW-A2E"> | ||
<objects> | ||
<viewController id="01J-lp-oVM" sceneMemberID="viewController"> | ||
<layoutGuides> | ||
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/> | ||
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/> | ||
</layoutGuides> | ||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3"> | ||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="53" y="375"/> | ||
</scene> | ||
</scenes> | ||
</document> |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>LSRequiresIPhoneOS</key> | ||
<true/> | ||
<key>UILaunchStoryboardName</key> | ||
<string>LaunchScreen</string> | ||
<key>UIMainStoryboardFile</key> | ||
<string>Main</string> | ||
<key>UIRequiredDeviceCapabilities</key> | ||
<array> | ||
<string>armv7</string> | ||
</array> | ||
<key>UISupportedInterfaceOrientations</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
<string>UIInterfaceOrientationLandscapeLeft</string> | ||
<string>UIInterfaceOrientationLandscapeRight</string> | ||
</array> | ||
</dict> | ||
</plist> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// NewRepoViewController.swift | ||
// RxSwiftiOS | ||
// | ||
// Created by Marin Todorov on 1/21/17. | ||
// Copyright © 2017 Underplot ltd. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
import RxSwift | ||
import RxCocoa | ||
|
||
class NewRepoViewController: UITableViewController { | ||
|
||
@IBOutlet var id: UITextField! | ||
@IBOutlet var name: UITextField! | ||
@IBOutlet var language: UITextField! | ||
@IBOutlet var saveButton: UIButton! | ||
|
||
private let bag = DisposeBag() | ||
private let repo = PublishSubject<Repo>() | ||
|
||
lazy var repoObservable: Observable<Repo> = { | ||
return self.repo.asObservable() | ||
}() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
bindUI() | ||
} | ||
|
||
func bindUI() { | ||
// current repo data | ||
let currentRepo = Observable.combineLatest(id.rx.text, name.rx.text, language.rx.text) { id, name, lang -> Repo? in | ||
guard let id = id, let idInt = Int(id), | ||
let name = name, name.characters.count > 1, | ||
let lang = lang, lang.characters.count > 0 else { | ||
return nil | ||
} | ||
return Repo(idInt, name, lang) | ||
} | ||
.shareReplay(1) | ||
|
||
// toggle save button | ||
currentRepo | ||
.map { $0 != nil } | ||
.bindTo(saveButton.rx.isEnabled) | ||
.addDisposableTo(bag) | ||
|
||
// emit repo when saved | ||
saveButton.rx.tap | ||
.withLatestFrom(currentRepo) | ||
.subscribe(onNext: {[weak self] repo in | ||
if let repo = repo { | ||
self?.repo.onNext(repo) | ||
self?.repo.onCompleted() | ||
} | ||
}) | ||
.addDisposableTo(bag) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// PresentViewController.swift | ||
// RxSwiftiOS | ||
// | ||
// Created by Marin Todorov on 1/21/17. | ||
// Copyright © 2017 Underplot ltd. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import RxSwift | ||
import RxCocoa | ||
|
||
private let initialRepos = [ | ||
Repo(1, "EasyAnimation", "Swift"), | ||
Repo(2, "Unbox", "Swift"), | ||
Repo(3, "RxSwift", "Swift") | ||
] | ||
|
||
class PresentViewController: UITableViewController { | ||
|
||
private let repos = Variable<[Repo]>(initialRepos) | ||
private let bag = DisposeBag() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
tableView.dataSource = nil | ||
bindUI() | ||
} | ||
|
||
func bindUI() { | ||
// display data | ||
repos.asObservable() | ||
.bindTo(tableView.rx.items) { (tableView, row, repo) in | ||
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")! | ||
cell.textLabel!.text = repo.name | ||
cell.detailTextLabel?.text = repo.language | ||
return cell | ||
} | ||
.addDisposableTo(bag) | ||
|
||
// present view controller, observe output | ||
navigationItem.rightBarButtonItem!.rx.tap | ||
.debounce(0.5, scheduler: MainScheduler.instance) | ||
.flatMapFirst {[weak self] _ -> Observable<Repo> in | ||
if let addVC = self?.storyboard?.instantiateViewController(withIdentifier: "NewRepoViewController") as? NewRepoViewController { | ||
self?.navigationController?.pushViewController(addVC, animated: true) | ||
return addVC.repoObservable | ||
} | ||
return Observable.never() | ||
} | ||
.subscribe(onNext: {[weak self] repo in | ||
self?.repos.value.append(repo) | ||
_ = self?.navigationController?.popViewController(animated: true) | ||
}) | ||
.addDisposableTo(bag) | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// Repo.swift | ||
// RxSwiftiOS | ||
// | ||
// Created by Marin Todorov on 1/21/17. | ||
// Copyright © 2017 Underplot ltd. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Repo { | ||
let id: Int | ||
let name: String | ||
let language: String | ||
|
||
init?(object: [String: Any]) { | ||
guard let id = object["id"] as? Int, | ||
let name = object["name"] as? String, | ||
let language = object["language"] as? String else { | ||
return nil | ||
} | ||
self.id = id | ||
self.name = name | ||
self.language = language | ||
} | ||
|
||
init(_ id: Int, _ name: String, _ language: String) { | ||
self.id = id | ||
self.name = name | ||
self.language = language | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// ViewController.swift | ||
// RxSwiftiOS | ||
// | ||
// Created by Marin Todorov on 1/21/17. | ||
// Copyright © 2017 Underplot ltd. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import Unbox | ||
|
||
import RxSwift | ||
import RxCocoa | ||
|
||
class SearchGitHubViewController: UIViewController { | ||
|
||
@IBOutlet var tableView: UITableView! | ||
@IBOutlet var searchBar: UISearchBar! | ||
|
||
private let bag = DisposeBag() | ||
private let repos = Variable<[Repo]>([]) | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
bindUI() | ||
} | ||
|
||
func bindUI() { | ||
// observe text, form request, bind table view to result | ||
searchBar.rx.text | ||
.orEmpty | ||
.filter { query in | ||
return query.characters.count > 2 | ||
} | ||
.debounce(0.5, scheduler: MainScheduler.instance) | ||
.map { query in | ||
let apiUrl = URL(string: "https://api.github.com/search/repositories?q=" + query)! | ||
return URLRequest(url: apiUrl) | ||
} | ||
.flatMapLatest { request in | ||
return URLSession.shared.rx.json(request: request) | ||
.catchErrorJustReturn([]) | ||
} | ||
.map { json -> [Repo] in | ||
guard let json = json as? [String: Any], | ||
let items = json["items"] as? [[String: Any]] else { | ||
return [] | ||
} | ||
return items.flatMap(Repo.init) | ||
} | ||
|
||
.bindTo(tableView.rx.items) { tableView, row, repo in | ||
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")! | ||
cell.textLabel!.text = repo.name | ||
cell.detailTextLabel?.text = repo.language | ||
return cell | ||
} | ||
.addDisposableTo(bag) | ||
} | ||
} |
Oops, something went wrong.