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
Everyday CoreData
Search
Pat Zearfoss
March 16, 2016
Technology
94
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Everyday CoreData
My CoreData talk at CodersOnly on March 16, 2016
Pat Zearfoss
March 16, 2016
More Decks by Pat Zearfoss
See All by Pat Zearfoss
CircleBack and WWDC 2015
pzearfoss
0
37
Other Decks in Technology
See All in Technology
Reactの設計論
uhyo
24
14k
新機種発売前に見直そう!端末移行で再ログインが要るアプリ・要らないアプリは何が違うのか 〜シームレスに再開できる設計と実装〜
zozotech
PRO
0
210
AIを活用するために決めた "やらないこと" - 価値に注目する / Not betting on AI
soudai
PRO
2
550
絵ではじめるKubernetesセキュリティ
aoi1
4
670
Vibe Coding で作ったプロダクトをどう安全に動かすか / How to Safely Run Products Built with Vibe Coding
glidenote
0
150
The Knowledge Spine: A Machine-Executable Ontology for Governed Marketing Activation
vananth22
0
100
登壇の自信を奪う3匹のオバケ / 3 Ghosts That Rob You of Your Confidence in Public Speaking
pauli
9
1k
AIエージェントの自己改善をどう設計するか / How to Design Self-Improvement for AI Agents
22mi
25
16k
「ピッケル本」日本語版は4.0(第6版)が出版されるべき / pickaxe4-nagoyark05
kakutani
2
180
負債のメタファと2026年 / Debt Metaphor in Agentic Engineering Age 202609 Edition
twada
PRO
9
4.1k
HHKBエバンジェリストになる方法
941
0
110
AIによるクリエイティブ生成を行う上での試行錯誤
plaidtech
PRO
0
160
Featured
See All Featured
Unsuck your backbone
ammeep
672
58k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Technical Leadership for Architectural Decision Making
baasie
3
570
30 Presentation Tips
portentint
PRO
1
400
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Code Reviewing Like a Champion
maltzj
528
40k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
520
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
400
Amusing Abliteration
ianozsvald
1
310
Transcript
Everyday CoreData Pat Zearfoss
About Me • Pat Zearfoss • CircleBack on the app
store • Running on a CoreData stack for better than a year. • @patzearfoss on Twitter.
End User License Agreement • My suggestions may not be
100% right for all situations • CoreData elicits a lot of opinions in the community. • Your app may not fit the same patterns and models
Lets Go
Things I’ll talk about • Frameworks and tools • Model
design • App architecture • Testing • Debugging tools
CoreData Review
CoreData Review • A way of persisting data in Cocoa
applications • Not a database • Well, it kind of is, but not necessarily • On label usage is “object graph persistence”
Object Graph
CoreData Pieces • NSManagedObjectModel • NSPesistentStoreCoordinator • NSManagedObjectContext • NSManagedObject
Tip #1 Once you understand CoreData, use a framework (or
write one) to make life easier.
There’s tons • Magical Record • BNRCoreData • RestKit
Why • It’ll help you simplify all the stuff you’ll
do anyway. • CoreData can be . . . wordy.
Creating a new instance if let eDesc = NSEntityDescription.entityForName(“Contact”, inManagedObjectContext:
context) { let contact1 = Contact(entity: contactDescription, insertIntoManagedObjectContext:context) }
A basic fetch let fetchRequest = NSFetchRequest(entityName: “Contact”) fetchRequest.sortDescriptors =
[NSSortDescriptor(key: “lastName”, ascending: true)] fetchRequest.predicate = NSPredicate(format: “isFavorite = YES”) if let context = context { do { try contacts = context. executeFetchRequest(fetchRequest) as! [Contact] } catch { print (“couldn’t load contacts”) } }
The app delegate eyebleed
Creating an instance - MR if let contact1 = Contact.MR_createEntityInContext(context)
Fetch if let fetchedContacts = Contact.MR_findAllSortedBy(“lastName”, ascending: true, inContext: context) as? [Contact]
Eyebleed cured MagicalRecord.setupCoreDataStack()
Demo 1
More tools • SimPholders • CoreDataEditor • SQLPro or other
Sqlite tool
Modeling • Your managed model is a database, but it
also isn’t. You have to make it work right for you.
Tip #2 Design for your app. Don’t feel the need
to appease the database gods.
Demo 2
Tip #3 Use NSManagedObjectContexts liberally • Creating a new context
to fetch objects, passing the ids to a main context for use on the UI. • Doing expensive operations in background queues • Creating a throw-away editing context.
Demo 3
Tip #4 NSFetchedResultsController can be your best friend • NSFetchedResultsController
manages the results of a fetch into a context.
NSFetchedResultsController • Keeping a UI updated with changes from the
internet. • Use fetched results controllers to manage all communication with a web backend.
Demo 4
Architectural patterns from fetched results controllers
None
Testing • You don’t really care about persistence • You
just want to test this object, controller, view model, etc.
Tip #5 Use an in-memory store for testing • Sets
up the same scheme you have in memory. • Quick and easy to set up an tear down between tests
Demo 5
Debugging
Tip #6 Learn and use the CoreData environment variables
Useful environment variables • com.apple.CoreData.SQLDebug [1,2,3] • com.apple.CoreData.SyntaxColoredLogging 1 •
com.apple.CoreData.ConcurrencyDebug 1 • (not ThreadDebug) • com.apple.CoreData.MigrationDebug
Demo 6
Tip #7 Use the CoreData tool in instruments
Demo 7 CircleBack App
Tip #8 Other people have really good ideas • Saul
Mora - original author of MagicalRecord • Marcus Zarra - wrote many a book on CoreData • objc.io on CoreData • WWDC Material (obvi)
Recap • Find a good framework to help you. •
Design a model that fits your app’s needs • Make use of NSManagedObjectContext • Use NSFetchedResultsControllers
Recap • Use in memory stores for testing • CoreData
runtime arguments are your friend • Make use of Instruments • Read good material
?s and Thanks! •
[email protected]
• @patzearfoss