Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
New Library for CoreData
Search
Muukii
July 13, 2015
Programming
2.9k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
New Library for CoreData
Muukii
July 13, 2015
More Decks by Muukii
See All by Muukii
Problem Solving from the Abstraction Layer
muukii0803
1
76
Pairs iOSとトレンドの技術
muukii0803
0
1.1k
Thoughts about build flow
muukii0803
2
360
スマホアプリ開発で大切なこと
muukii0803
3
200
エンジニアとして働くために
muukii0803
0
220
Q. Textureは部分的に導入できますか?
muukii0803
3
2.6k
安定したチャットを実現するための アプリとAPI設計
muukii0803
17
8.6k
快適なUIを持つアプリを作るために できること
muukii0803
12
2.8k
iOS エンジニアが考える Webアプリ開発
muukii0803
3
540
Other Decks in Programming
See All in Programming
iOSDC2026登壇資料.pdf
riofujimon
0
170
スマート反転とウェブアクセシビリティ
camiha
0
210
速習iPhone Duo対応
yuukiw00w
1
710
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
500
Workers Cache を知る
syumai
0
130
Java 27新機能 / Java 27 new features
kishida
2
150
すこし踏み込む CancellationToken
htkym
2
710
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
300
TiDB Cloudのカスタムコントローラーによるオートスケール対応
takaidohigasi
0
130
Security issues being discussed on Web Platforms
petamoriken
0
1k
Verilogで学ぶCPU自作入門.pdf
uyuki234
1
370
WebAssembly in Android Apps 〜 WASMはJNIの夢を見るか
keiji
1
110
Featured
See All Featured
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
4 Signs Your Business is Dying
shpigford
187
23k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Writing Fast Ruby
sferik
630
63k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Tell your own story through comics
letsgokoyo
1
1.1k
Making Projects Easy
brettharned
120
6.8k
Navigating Team Friction
lara
192
16k
Evolving SEO for Evolving Search Engines
ryanjones
0
300
Mobile First: as difficult as doing things right
swwweet
225
10k
Transcript
New Library for CoreData Hiroshi Kimura potatotips #19
ଜ Hiroshi Kimura iOS Developer eureka, Inc. @muukii0803
None
None
None
CoreStore https://github.com/JohnEstropia/CoreStore
Developer Hiroshi Kimura eureka, Inc. @muukii0803 John Estropia eureka, Inc.
@JohnEstropia
Good things :)
Good things :) • SwiftͰॻ͔Ε͍ͯΔ
Good things :) • SwiftͰॻ͔Ε͍ͯΔ • ϝΠϯεϨουͷContextRead-Only ॻ͖ࠐΈͯ͢SerialʹBackgroundContextͰߦΘΕΔͨΊɺ ҆શʹಈ࡞͢Δઃܭ
Good things :) • SwiftͰॻ͔Ε͍ͯΔ • ϝΠϯεϨουͷContextRead-Only ॻ͖ࠐΈͯ͢SerialʹBackgroundContextͰߦΘΕΔͨΊɺ ҆શʹಈ࡞͢Δઃܭ •
ෳͷSQLiteϑΝΠϧ͕༻Մೳ (ConfigurationͰ͚Δ)
Good things :) • SwiftͰॻ͔Ε͍ͯΔ • ϝΠϯεϨουͷContextRead-Only ॻ͖ࠐΈͯ͢SerialʹBackgroundContextͰߦΘΕΔͨΊɺ ҆શʹಈ࡞͢Δઃܭ •
ෳͷSQLiteϑΝΠϧ͕༻Մೳ (ConfigurationͰ͚Δ) • Observer͕༻ҙ͞Ε͍ͯΔ (FRCΛॻ͔ͳͯ͘ྑ͘ͳΔ)
Good things :) • SwiftͰॻ͔Ε͍ͯΔ • ϝΠϯεϨουͷContextRead-Only ॻ͖ࠐΈͯ͢SerialʹBackgroundContextͰߦΘΕΔͨΊɺ ҆શʹಈ࡞͢Δઃܭ •
ෳͷSQLiteϑΝΠϧ͕༻Մೳ (ConfigurationͰ͚Δ) • Observer͕༻ҙ͞Ε͍ͯΔ (FRCΛॻ͔ͳͯ͘ྑ͘ͳΔ) • ϚΠάϨʔγϣϯΛαϙʔτ
Usage
DataStack struct Stack { static let data: DataStack = {
let dataStack = DataStack(modelName: "CoreData") dataStack.addSQLiteStoreAndWait( "CoreData.sqlite", configuration: nil, resetStoreOnMigrationFailure: true ) return dataStack }() } SQLiteʹඥͮ͘DataStackΛੜ͠·͢
struct Stack { static let dataA: DataStack = { let
dataStack = DataStack(modelName: "StackSetupDemo") dataStack.addSQLiteStoreAndWait( "CoreData.sqlite", configuration: "Configuration_A", resetStoreOnMigrationFailure: true ) return dataStack }() static let dataB: DataStack = {...} static let dataC: DataStack = {...} } Configuration͝ͱʹDataStackͷੜ͕Մೳ ࠓճConfigurationΛΘͳ͍ํ๏ͰਐΊ͍͖ͯ·͢ɻ
let people = Stack.data.fetchAll( From(MyPersonEntity), Where("age > 30"), OrderBy(.Ascending("name"), .Descending("age")),
Tweak { (fetchRequest) -> Void in fetchRequest.includesPendingChanges = false } ) Fetch NSSortDescriptor, NSPredicateΘͣʹࢦఆ ࡉ͔͍ઃఆTweakͰࢦఆՄೳ
Stack.data.beginAsynchronous { (transaction) -> Void in let qrcode = transaction.create(Into(QRCode))
let codes = transaction.fetch( . . . ) transaction.commit() { result in switch result { case .Success(let hasChanges): success?() case .Failure(let error): failure?(error: error) } } } Create - Update
ViewController Fetch - Observe
Fetch
Controller͔ΒCoreDataΛ͏࣌ͬͯ
Controller͔ΒCoreDataΛ͏࣌ͬͯ NSFetchedResultsController ?
Controller͔ΒCoreDataΛ͏࣌ͬͯ
Controller͔ΒCoreDataΛ͏࣌ͬͯ ManagedObjectListController
var codes: ManagedObjectListController<QRCode> = { return Stack.data.observeObjectList( From(QRCode), Where("removed ==
false”), OrderBy(.Descending("readAt")) ) }() Controllerʹදࣔ͢ΔΦϒδΣΫτͷ݅Λࢦఆ
codes.numberOfSections() SectionͷΛऔಘ
codes.numberOfObjectsInSection(section) Section͔ΒObjectͷΛऔಘ
let code = codes[indexPath] NSIndexPath͔ΒObjectΛऔಘ
Observe
codes.removeObserver(self) codes.addObserver(self) Observe Observeͷ։࢝ Observeͷऴྃ
protocol ManagedObjectListChangeObserver • WillChange • Insert • Delete • Update
• Move • InsertSection • deleteSection • DidChange GenericsͰ࣮͞Ε͍ͯΔͨΊɺas ͕ෆཁ
Conclusion • DataStackΛϕʔεʹಈ࡞͢Δ • Fetchͷهड़͕γϯϓϧ • DataStack͝ͱʹγϦΞϧΩϡʔͰಈ࡞͢ΔͨΊ҆શ • ViewControllerͱͷ࿈ܞ͕؆୯ •
ϚΠάϨʔγϣϯ͕ॆ࣮ ΠϯΫϦϝϯλϧʹϚΠάϨʔγϣϯ͢Δ͜ͱՄೳ • GenericsͰ࣮͞Ε͍ͯΔͨΊμΠφϛοΫΩϟετ͕ݮΒͤΔ
Swift2.0
Thank you :)
Thank you :)