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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Kishikawa Katsumi
July 24, 2016
Programming
1
320
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
浮動小数の比較について
kishikawakatsumi
0
65
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
200
愛される翻訳の秘訣
kishikawakatsumi
3
390
Private APIの呼び出し方
kishikawakatsumi
3
980
iOSでSVG画像を扱う
kishikawakatsumi
0
220
Build your own WebP codec in Swift
kishikawakatsumi
2
1.6k
iOSDC 2024 SMBファイル共有をSwiftで実装する
kishikawakatsumi
1
290
Enhancing Applications with Accessibility API
kishikawakatsumi
3
5.2k
Mastering SwiftSyntax
kishikawakatsumi
4
7.5k
Other Decks in Programming
See All in Programming
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
180
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
210
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.7k
CSC307 Lecture 09
javiergs
PRO
1
840
Best-Practices-for-Cortex-Analyst-and-AI-Agent
ryotaroikeda
1
110
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
510
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
OSSとなったswift-buildで Xcodeのビルドを差し替えられるため 自分でXcodeを直せる時代になっている ダイアモンド問題編
yimajo
3
630
生成AIを活用したソフトウェア開発ライフサイクル変革の現在値
hiroyukimori
PRO
0
110
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
300
Raku Raku Notion 20260128
hareyakayuruyaka
0
370
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
620
Featured
See All Featured
Faster Mobile Websites
deanohume
310
31k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
130
Technical Leadership for Architectural Decision Making
baasie
2
250
Code Review Best Practice
trishagee
74
20k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Paper Plane (Part 1)
katiecoart
PRO
0
4.3k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
140
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
190
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
950
Designing for Performance
lara
610
70k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.9k
Git: the NoSQL Database
bkeepers
PRO
432
66k
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