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
3.1k
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
810
Other Decks in Technology
See All in Technology
サイバーセキュリティと認知バイアス:対策の隙を埋める心理学的アプローチ
shumei_ito
0
380
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
3.8k
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
300
SREによる隣接領域への越境とその先の信頼性
shonansurvivors
2
510
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
いざ、BSC討伐の旅
nikinusu
2
770
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
Why does continuous profiling matter to developers? #appdevelopercon
salaboy
0
180
Terraform未経験の御様に対してどの ように導⼊を進めていったか
tkikuchi
2
420
AWS Lambda のトラブルシュートをしていて思うこと
kazzpapa3
2
170
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Gamification - CAS2011
davidbonilla
80
5k
The Language of Interfaces
destraynor
154
24k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Building Adaptive Systems
keathley
38
2.3k
For a Future-Friendly Web
brad_frost
175
9.4k
A Philosophy of Restraint
colly
203
16k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
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.