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
分析の民主化を支えるメタデータ整備の実践
kakehashi
PRO
4
1.4k
遠藤な_めぐろLT #38 「社内のAI活用推進」@麻布台_20261009
endonanana
0
130
V8のArray.prototype.flatを最大約20倍速くするまでと、巨大OSSへの大規模コミットの道のり
riyaamemiya
0
290
ブラウザとサーバーから考えるAI時代のフロントエンド監視
shogo4131
3
940
Code for Security プロジェクト紹介 2026年10月
yu23ki14
0
110
子育てエンジニアの可処分時間が減っても成長を諦めない戦い方
sudoakiy
6
4.6k
WasmをRustにする
sansantech
PRO
0
250
NDIでApple Vision Proにリアルタイム映像送信
jyouryuusui
0
120
hackers_champloo_2026_tidb
makocchi
0
160
DGX Spark でどこまでハッキングができるのか?
kash1064
3
1.3k
QA4AI 2026-Oct 生成AI時代の品質保証
tokuty
1
860
UniFi(ユニファイ)AIカメラの現場活用
ludicmind
1
440
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Crafting Experiences
bethany
1
380
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
59k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
550
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
67k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
410
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
950
From π to Pie charts
rasagy
1
400
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
780
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
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