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
プロダクト成長に対応するプラットフォーム戦略:Authleteによる共通認証基盤の移行事例 / Building an authentication platform using Authlete and AWS
kakehashi
1
150
[JAWS-UG金沢支部×コンテナ支部合同企画]コンテナとは何か
furuton
3
250
グローバル展開を見据えたサービスにおける機械翻訳プラクティス / dp-ai-translating
cyberagentdevelopers
PRO
1
150
[AWS JAPAN 生成AIハッカソン] Dialog の紹介
yoshimi0227
0
150
フルカイテン株式会社 採用資料
fullkaiten
0
36k
端末が簡単にリモートから操作されるデモを通じて ソフトウェアサプライチェーン攻撃対策の重要性を理解しよう
kitaji0306
0
170
初心者に Vue.js を 教えるには
tsukuha
5
390
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
3.6k
【若手エンジニア応援LT会】AWS Security Hubの活用に苦労した話
kazushi_ohata
0
160
【技術書典17】OpenFOAM(自宅で極める流体解析)2次元円柱まわりの流れ
kamakiri1225
0
210
GitHub Universe: Evaluating RAG apps in GitHub Actions
pamelafox
0
170
Jr. Championsになって、強く連携しながらAWSをもっと使いたい!~AWSに対する期待と行動~
amixedcolor
0
190
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
93
13k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
790
RailsConf 2023
tenderlove
29
880
GitHub's CSS Performance
jonrohan
1030
460k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
7
150
Making Projects Easy
brettharned
115
5.9k
A Philosophy of Restraint
colly
203
16k
BBQ
matthewcrist
85
9.3k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
32
1.8k
Learning to Love Humans: Emotional Interface Design
aarron
272
40k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.2k
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.