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.6k
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
7k
ReduxDevTools' power to the iOS development
susieyy
0
820
Other Decks in Technology
See All in Technology
非機能品質を作り込むための実践アーキテクチャ
knih
2
630
第3回Snowflake女子会_LT登壇資料(合成データ)_Taro_CCCMK
tarotaro0129
0
180
GitHub Copilot のテクニック集/GitHub Copilot Techniques
rayuron
23
11k
AIのコンプラは何故しんどい?
shujisado
1
190
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
150
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
300
権威ドキュメントで振り返る2024 #年忘れセキュリティ2024
hirotomotaguchi
2
730
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
250
5分でわかるDuckDB
chanyou0311
10
3.2k
生成AIのガバナンスの全体像と現実解
fnifni
1
180
WACATE2024冬セッション資料(ユーザビリティ)
scarletplover
0
190
サイバー攻撃を想定したセキュリティガイドライン 策定とASM及びCNAPPの活用方法
syoshie
3
1.2k
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
For a Future-Friendly Web
brad_frost
175
9.4k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Gamification - CAS2011
davidbonilla
80
5.1k
A designer walks into a library…
pauljervisheath
204
24k
Building Adaptive Systems
keathley
38
2.3k
RailsConf 2023
tenderlove
29
940
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Producing Creativity
orderedlist
PRO
341
39k
Practical Orchestrator
shlominoach
186
10k
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.