Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Realm meetup Japan #17
Search
Kishikawa Katsumi
July 24, 2016
Programming
1
310
Realm meetup Japan #17
- Realm Objective-C/Swift 1.0.2
- RxRealm
Kishikawa Katsumi
July 24, 2016
Tweet
Share
More Decks by Kishikawa Katsumi
See All by Kishikawa Katsumi
iOSDC 2024 SMBファイル共有をSwiftで実装する
kishikawakatsumi
1
160
Enhancing Applications with Accessibility API
kishikawakatsumi
3
3.2k
Mastering SwiftSyntax
kishikawakatsumi
4
5.3k
My SwiftData Review
kishikawakatsumi
7
1.4k
Swift Expression Macros: a practical introduction
kishikawakatsumi
3
1.8k
Xcode Cloudの評価
kishikawakatsumi
2
1.2k
Regular expressions basics/正規表現の基本
kishikawakatsumi
7
720
家のいろいろな数値を計測する
kishikawakatsumi
4
2.2k
GitHub Actionsでテストの結果をわかりやすく表示する
kishikawakatsumi
1
1k
Other Decks in Programming
See All in Programming
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
610
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
180
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
Jakarta EE meets AI
ivargrimstad
0
550
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Ethereum_.pdf
nekomatu
0
460
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.3k
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
330
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
The Invisible Side of Design
smashingmag
298
50k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
Faster Mobile Websites
deanohume
305
30k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Rails Girls Zürich Keynote
gr2m
94
13k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Transcript
Realm meetup #17
[email protected]
Katsumi Kishikawa Realm Inc.
[email protected]
Recent Updates
[email protected]
Recent Updates • Realm Objective-C/Swift 1.0.2 (was 1.0.1) • Realm
Java 1.1.0 (was 1.0.1) • Realm React Native 0.14.0 (was 0.13.0) • Realm Xamarin 0.76.0
[email protected]
[email protected]
Realm Objective-C/Swift 1.0.2 (was 1.0.1)
[email protected]
Realm Objective-C/Swift 1.0.2 • ϓϩύςΟ͕ଘࡏ͠ͳ͍ΫϥεΛอଘ͠Α͏ͱ͢Δͱྫ֎ʹ • write(_:)ϝιουͷϒϩοΫͰthrowͰ͖ΔΑ͏ʹ • όΠφϦαΠζ͕গ͠ݮগ •
addNotificationBlock(_:, change:)Ͱॳճͷݺͼग़͠ඞ ͣ.Initial͕ݺΕΔΑ͏ʹ • ٯํͷؔ࿈͕มߋʹͳΔ߹ʹ௨͕ݺΕͳ͍Λमਖ਼
[email protected]
[email protected]
Already compatible with Swift 3 & Xcode 8 https://github.com/realm/realm-cocoa/issues/3796
[email protected]
Protip for Xcode 8 beta3 and Carthage
[email protected]
$ echo
SWIFT_VERSION=\"3.0\">swift3.xcconfig $ XCODE_XCCONFIG_FILE=`pwd`/swift3.xcconfig \ carthage update --platform iOS --no-use-binaries
RxSwift & Realm
[email protected]
What’s Rx?
[email protected]
What’s Rx?
[email protected]
[1, 2, 3, 4, 5, 6]
What’s Rx?
[email protected]
[1, 2, 3, 4, 5, 6] .filter
{ $0 % 2 == 0 }
What’s Rx?
[email protected]
[1, 2, 3, 4, 5, 6] .map
{ $0 * 5 }
What’s Rx?
[email protected]
Array<T> => Observable<T>
RxRealm https://github.com/RxSwiftCommunity/RxRealm
[email protected]
Using RxRealm
[email protected]
pod 'RxSwift' pod 'RxCocoa' pod 'RealmSwift' pod
'RxRealm'
RxRealm makes Realm observable
[email protected]
Realm.asObservable() Results.asObservable() List.asObservable() LinkingObjects.asObservable() AnyRealmCollection.asObservable()
RxRealm makes Realm observable
[email protected]
Results.asObservableArray() List.asObservableArray() LinkingObjects.asObservableArray() AnyRealmCollection.asObservableArray()
RxRealm makes Realm observable
[email protected]
Realm.asObservableChangeset() Results.asObservableChangeset() List.asObservableChangeset() LinkingObjects.asObservableChangeset() AnyRealmCollection.asObservableChangeset()
RxRealm makes Realm observable
[email protected]
Realm.asObservableChangesetArray() Results.asObservableChangesetArray() List.asObservableChangesetArray() LinkingObjects.asObservableChangesetArray() AnyRealmCollection.asObservableChangesetArray()
RxRealm makes Realm observable
[email protected]
Realm.rx_add() Realm.rx_delete()
RxRealm makes Realm observable
[email protected]
public func asObservable() -> Observable<Self>
{ return Observable.create {observer in let token = self.addNotificationBlock {changeset in let value: Self switch changeset { case .Initial(let latestValue): value = latestValue case .Update(let latestValue, _, _, _): value = latestValue case .Error(let error): observer.onError(error) return } observer.onNext(value) } return AnonymousDisposable { observer.onCompleted() token.stop() } } }
RxRealm makes Realm observable
[email protected]
public func asObservable() -> Observable<Self>
{ return Observable.create {observer in let token = self.addNotificationBlock {changeset in let value: Self ... observer.onNext(value) } return AnonymousDisposable { observer.onCompleted() token.stop() } } }
RxRealm makes Realm observable
[email protected]
public func asObservable() -> Observable<Self>
{ return Observable.create {observer in let token = self.addNotificationBlock {changeset in let value: Self ... observer.onNext(value) } return AnonymousDisposable { observer.onCompleted() token.stop() } } }
RxRealm makes Realm observable
[email protected]
public extension NotificationEmitter where Self:
RealmCollectionType { public func asObservable() -> Observable<Self> { return Observable.create {...} } }
RxRealm makes Realm observable
[email protected]
public protocol NotificationEmitter { func
addNotificationBlock(block: (RealmCollectionChange<Self>) -> ()) -> NotificationToken } extension List: NotificationEmitter {} extension AnyRealmCollection: NotificationEmitter {} extension Results: NotificationEmitter {} extension LinkingObjects: NotificationEmitter {}
RxRealm makes Realm observable
[email protected]
public extension NotificationEmitter where Self:
RealmCollectionType { public func asObservable() -> Observable<Self> { return Observable.create {...} } }
Usage
[email protected]
var token: NotificationToken? func searchWithText(text: String) { token
= realm .objects(Location) .filter("...") .sorted("...") .addNotificationBlock { (...) in ... tableView.reloadData() } ... }
Usage
[email protected]
realm .objects(Location) .filter("address CONTAINS %@", query) .sorted("identifier") .asObservable()
.subscribeNext {[unowned self]results in ... }.addDisposableTo(self.bag)
Example
[email protected]
/* Observable<Results<Lap>> - wrap Results as observable */
realm.objects(Lap).asObservable() .map {laps in "\(laps.count) laps"} .subscribeNext {[unowned self]text in self.title = text } .addDisposableTo(bag) /* Observable<Array<Lap>> - convert Results to Array and wrap as observable */ realm.objects(Lap).sorted("time", ascending: false).asObservableArray() .map {array in array.prefix(5) } .bindTo(tableView.rx_itemsWithCellIdentifier("Cell", cellType: UITableViewCell.self)) {row, element, cell in cell.textLabel!.text = formatter.stringFromDate(NSDate(timeIntervalSinceReferenceDate: element.time)) }.addDisposableTo(bag) /* Use bindable sinks to add objects */ addOneItemButton.rx_tap .map { Lap() } .bindTo(Realm.rx_add()) .addDisposableTo(bag) addTwoItemsButton.rx_tap .map { [Lap(), Lap()] } .bindTo(Realm.rx_add()) .addDisposableTo(bag)
Incremental search
[email protected]
class ViewController: UIViewController, UISearchBarDelegate, UITableViewDataSource { ...
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return results.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { cell = ... item = results[indexPath.row] cell.textLabel.text = ... return cell } func searchWithText(text: String) { realm .objects(Location) .filter("...") .sorted("...") .addNotificationBlock { (...) in ... } ... tableView.reloadData() } func searchBar(searchBar: UISearchBar, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool { ... searchWithText(text) return true }
Incremental search
[email protected]
class ViewController: UIViewController { let bag =
DisposeBag() let realm = try! Realm() @IBOutlet weak var searchBar: UISearchBar! @IBOutlet weak var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() searchBar .rx_text .subscribeNext { [unowned self] (query) in self.realm .objects(Location) .filter("address CONTAINS %@", query) .sorted("identifier") .asObservable() .bindTo(self.tableView.rx_itemsWithCellIdentifier("Cell", cellType: UITableViewCell.self)) {( cell.textLabel!.text = element.address self.tableView.reloadData() }.addDisposableTo(self.bag) } .addDisposableTo(bag) }
Where to find us • ! Realm Japan User Group:
facebook.com/groups/realmjp • ! Twitter: twitter.com/realmJapan • GitHub: github.com/realm • ! StackOverflow: ja.stackoverflow.com/questions/tagged/realm • ! Email:
[email protected]
• ! Slack: slack.realm.io/
[email protected]
[email protected]
Realm Japan User Group Facebook
[email protected]
Support Chat Slack
[email protected]
Ξϯέʔτ http://bit.ly/RealmJP_17
[email protected]
Questions? Katsuma Kishikawa
[email protected]
www.realm.io/jp @k_katsumi