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
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
3
620
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
9
1.1k
Terraform Stacks入門 #HashiTalks
msato
0
360
Lexical Analysis
shigashiyama
1
150
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
130
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
390
Taming you application's environments
salaboy
0
190
Lambdaと地方とコミュニティ
miu_crescent
2
370
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.8k
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
420
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
37
12k
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The World Runs on Bad Software
bkeepers
PRO
65
11k
KATA
mclloyd
29
14k
Building Adaptive Systems
keathley
38
2.3k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Bash Introduction
62gerente
608
210k
Git: the NoSQL Database
bkeepers
PRO
427
64k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
RailsConf 2023
tenderlove
29
900
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.