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
No Realm, No Life
Search
yohei sugigami
August 26, 2015
Technology
7
2.6k
No Realm, No Life
Realm meetup #6 で発表したSync iOSでのRealmの活用についてです
yohei sugigami
August 26, 2015
Tweet
Share
More Decks by yohei sugigami
See All by yohei sugigami
Snapshot Testing in iOS
susieyy
6
3k
Redux with iOS
susieyy
0
1.2k
Why use Redux in iOS
susieyy
5
2.5k
ReduxRxを活用したアプリアーキテクチャ
susieyy
8
2.3k
Redux+Rxを活用したiOSアプリアーキテクチャ
susieyy
10
1.9k
Swaggerで始めるAPI定義管理とコードジェネレート
susieyy
14
7.4k
開発中のアプリをXcode9 & Swift4に移行しました
susieyy
0
3.6k
Wantedly People ViewModel and Rx
susieyy
7
6.9k
ReduxDevTools' power to the iOS development
susieyy
0
800
Other Decks in Technology
See All in Technology
都市伝説バスターズ「WebアプリのボトルネックはDBだから言語の性能は関係ない」 - Kaigi on Rails 2024
osyoyu
13
4.8k
日経ビジュアルデータにおける スクロールテリングと地図/nikkei-tech-talk-26
nikkei_engineer_recruiting
0
160
WINTICKETアプリで実現した高可用性と高速リリースを支えるエコシステム / winticket-eco-system
cyberagentdevelopers
PRO
1
170
顧客が本当に必要だったもの - パフォーマンス改善編 / Make what is needed
soudai
21
5.8k
Figma Dev Modeで進化するデザインとエンジニアリングの協働 / figma-with-engineering
cyberagentdevelopers
PRO
1
340
端末が簡単にリモートから操作されるデモを通じて ソフトウェアサプライチェーン攻撃対策の重要性を理解しよう
kitaji0306
0
150
Capybara+生成AIでどこまで本当に自然言語のテストを書けるか?
yusukeiwaki
6
1.1k
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
3.6k
ABEMA のコンテンツ制作を最適化!生成 AI x クラウド映像編集システム / abema-ai-editor
cyberagentdevelopers
PRO
1
130
Mackerelが取り組むオブザーバビリティ - Mackerel Tech Day
mackerelio
0
330
[PyCon Korea 2024] Lightning Talk: PyPI패키지를 의심하세요
studioego
PRO
0
130
オニオンアーキテクチャで実現した 本質課題を解決する インフラ移行の実例
hryushm
13
2.7k
Featured
See All Featured
Unsuck your backbone
ammeep
668
57k
Fireside Chat
paigeccino
32
3k
Rails Girls Zürich Keynote
gr2m
93
13k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
How to Think Like a Performance Engineer
csswizardry
19
1.1k
Designing for humans not robots
tammielis
249
25k
Producing Creativity
orderedlist
PRO
341
39k
The Art of Programming - Codeland 2020
erikaheidi
51
13k
Bash Introduction
62gerente
608
210k
A Tale of Four Properties
chriscoyier
156
23k
Teambox: Starting and Learning
jrom
132
8.7k
Facilitating Awesome Meetings
lara
49
6k
Transcript
No Realm, No Life yohei SUGIGAMI Realm 08/25 Realm Meetup
#6
None
iOS DBวྺ ɾ'.%# ɾ$PSF%BUB ɾ.BHJDBM3FDPSE ɾ:BQ%BUBCBTF ɾ0CKFDUJWF-FWFM%# ɾ$PVDICBTF-JUF ɾ3FBMN 3FBMN
㱺࣮͕͋ΓɺυΩϡϝϯτἧ͍ͬͯΔ ɹ͍͍͢ɺύϑΥʔϚϯε͕ྑ͍ɺαϙʔτ͕ް͍
ઃܭ͕Ϟμϯ
͞ਖ਼ٛ
υΩϡϝϯτ͕ἧ͍ͬͯΔ
αϙʔτ͕ް͍
How using Realm
Sync iOS ϏδωείϛϡχέʔγϣϯಛԽϝοηʔδϯάαʔϏε Powered by RealmCocoa
For our UX requirements Ϣʔβʹ௨৴தͷͪΛײͤ͡͞ͳ͍Α͏ʹ 㱺ઌಡΈऔಘɺ௨ৗऔಘͷΩϟογϡͷ׆༻ Realm Ωϟγϡ
For our UX requirements ೖྗதɺૹ৴த ࣦഊʣͳͲͷ్தঢ়ଶͷ෮ݩ 㱺ঢ়ଶͷӬଓԽͷ׆༻ Realm ӬଓԽ
̎ Realm Databases 3FBMNҟͳΔϑΝΠϧύεͰ%#Λ ෳಉ࣌ʹѻ͏͜ͱ͕Ͱ͖Δ Realm ӬଓԽ༻ Ωϟγϡ༻ 㱺εΩʔϚఆٛશ%#ڞ௨ʹͳΔͷͰ ݸผʹϚΠάϨʔγϣϯΛߦ͑ͳ͔ͬͨͨΊࠓճݟૹΓ
$BSUpMF HJUIVCSFBMNSFBMNDPDPB ɹɹ How install realm-cocoa $BSUIBHFܦ༝ͰΠϯετʔϧ $PDPB1PETͩͱ4XJGUϥΠϒϥϦͷίϯύΠϧ͕͍ͨΊ 4XJGUܥϥΠϒϥϦੵۃతʹ$BSUIBHFͰΠϯετʔϧ 3FBMN4XJGUΛར༻
݄̔̎̏࣌ͷ࠷৽W
Realm Objects (SPVQ 6TFS 6TFS .FTTBHF 6TFS *NBHF 'JMF <.FNCFSTIJQ>
-JOL <.FOUJPO> 5PUBMNPEFMT
Introduce Realm ։ൃॳظ͔Β3FBMNΛಋೖͨ͠Θ͚Ͱͳ͘ ։ൃͷ్த͔ΒಋೖʢΩϟγϡɺӬଓԽػߏͷͳ͍ঢ়ଶʣ 1VSF$MBTTΛ3FBMN0CKFDUܧঝ ϓϩύςΟΛ3FBMNܗࣜʹ ؆୯ʹಋೖͰ͖·ͨ͠
RealmObject final class Message: Object { dynamic var user =
User() dynamic var image = MessageImage() dynamic var file = MessageFile() dynamic var link = MessageLink() dynamic var channelId = "" dynamic var content = "" var avatarImageURL: NSURL { return NSURL(string: user.avatarImageURL)! } class func fromJSONInner(json: JSON) -> Message { let message = Message() message.messageId = json["message_id"].stringValue message.content = json["content"].stringValue if json["image"].null == nil { message.image = MessageImage.fromJSON(json["image"]) } if json["file"].null == nil { message.file = MessageFile.fromJSON(json["file"]) } /463-1SJNJUJWF 4USJOH Ͱอଘͯ͠$PNQVUFE1SPQFSUZͰදݱ +40/͔Β0CKFDUΛ࡞
RealmObject enum MobileNotificationPreference: String { case AllActivities = "all_activities" case
OnlyMentions = "only_mentions" case Nothing = "nothing" } final class Group: Object { dynamic var mobileNotificationPreferenceRaw: String = MobileNotificationPreference.OnlyMentions.rawValue var mobileNotificationPreference: MobileNotificationPreference { return MobileNotificationPreference(rawValue: mobileNotificationPreferenceRaw) } FOVNͦͷ··อଘͰ͖ͳ͍ͷͰ3BXͰอଘͯ͠ $PNQVUFE1SPQFSUZͰදݱ
RealmObject final class Message: Object { … override class func
primaryKey() -> String { return "messageId" } override class func indexedProperties() -> [String] { return ["groupId"] } override class func ignoredProperties() -> [String] { return ["groupName"] } QSJNBSZ,FZ JOEFYFE1SPQFSUJFT JHOPSFE1SPQFSUJFTΛઃఆ
RealmObject final class Message: Object { … class func find(pkey:
String) -> Message? { return Realm().objectForPrimaryKey(Message.self, key: pkey) } class func findByChannel(groupId: String) -> Results<Message> { let predicate = NSPredicate(format: "groupId = %@", groupId) return Realm().objects(Message).filter(predicate) .sorted("createdAtRaw", ascending: false) } 3FBMNͷPCKFDUܥϝιουΛϥοϓͯ͠4VHBS4ZOUBYΛ࡞
Background // Queue let RealmBackgroundSaveQueue = dispatch_queue_create ("com.wantedly.sync.realm", DISPATCH_QUEUE_SERIAL) class
func saveJSON(json: JSON, closure: (group: Group) -> Void) { Async.customQueue(RealmBackgroundSaveQueue) { Realm().write { let group = Group.fromJSON(json) Realm().add(group, update: true) } Async.main { let group = Group.fromJSON(json) closure(group: group) } } } 3FBMNߋ৽ઐ༻ͷ4FSJBM2VFVFΛ࡞ͯ͠ஞ࣍తʹߋ৽ #BDLHSPVOEͰ࡞ͨ͠3FBMN0CKFDU.BJOͰ৮ΔͱΫϥογϡ อଘ༻ͱར༻༻Ͱ͚ͯΠϯελϯεΛ࡞ "TZOD4XJGUͷ($%Λϥοϓ͢ΔϥΠϒϥϦ
Migration // MARK: Initialize extension AppDelegate { func initializeRealm() {
let BuildVersion = NSBundle.mainBundle() .objectForInfoDictionaryKey("CFBundleVersion") as! String let thisVersion = UInt64(BuildVersion.toInt()!) setSchemaVersion(thisVersion, Realm.defaultPath) { migration, oldSchemaVersion in if oldSchemaVersion < thisVersion { // Nothing to do } } logger.debug("Realm Default Path [\(Realm.defaultPath)]") } } େͷ.JHSBUJPOͱͬͯ؆୯ 4DIFNB7FSTJPOΛ্͛Δ͚ͩ 4ZODͰ$'#VOEMF7FSTJPOͱ࿈ಈͯࣗ͠ಈԽ
ɾ։ൃ͍͢͠ ɾӡ༻͍͢͠ ɾΤϯδχΞʹ͍͞͠ Conclusion ɾ͏$PSF%BUBʹΕͳ͍
Enjoy Realm life.