Unleash Core Data: Fetching Data, Migrating, and Maintaining Persistent Stores
- Length: 346 pages
- Edition: 1
- Language: English
- Publisher: Apress
- Publication Date: 2022-09-09
- ISBN-10: 1484282108
- ISBN-13: 9781484282106
- Sales Rank: #0 (See Top 100 Books)
Create apps with rich capabilities to receive, process, and intelligently store data that work across multiple devices in the Apple ecosystem. This book will show you how to organize your app’s data and make it work for you and your users!
With many frameworks, there’s a point in the learning curve where you stop fearing the mountain of knowledge to learn and just enjoy the power to play and develop. For some reason many developers feel that point seems harder to reach with Core Data. And that’s unjustified―Core Data is a great framework that with powerful, optimized tools right out of the box. So it’s time you stopped fearing the journey and took your steps further out into the world of enjoying the power of Core Data.
With what you learn, you can build apps to deal with a large amount of data and complex relationships in intelligent and efficient ways. Core Data has many secrets underneath the hood that can power up your persistent store like never before. Tools such as Undo, objects deletion, migration, and more. Set up your store and your data model, handle objects with a multi-threading environment, write integration tests, and share your data with an Apple Watch app and iCloud.
What You’ll Learn
- Work with Core Data objects across apps and platforms
- Write integration tests with your persistent store
- Fetch, organize, write, and process data efficiently and intelligently
Who This Book Is For
Experienced iOS developers with Swift knowledge creating iOS apps that require saving complex data on the device other than a few numbers or text.
Table of Contents About the Author About the Technical Reviewer Chapter 1: Welcome to Core Data How I Met Core Data Why Is Core Data So Important? Because It Defines Your Business Because It Holds User Data Because That’s What We Sync A Little Bit About Core Data History NeXT and Enterprise Objects Framework Core Data Was Born What Will You Learn in This Book? Should You Be Using Core Data? How to Read This Book? Let’s Begin! Chapter 2: Core Data Basics and Setup What Exactly Is Core Data? The Core Data Developer Experience The Core Data Stack Why “Stack”? Creating the Core Data Stack The Managed Data Model Creating a Managed Data Model Add the Managed Object Model to Our Stack The Persistent Store Four Store Types In Memory SQLite Binary and XML Store Types Custom Store Type The Context Core Data Container Accessing Context More Configurations Let Apple Create the Container for Us UIKit-Based App SwiftUI-Based App SwiftUI Uniqueness Summary Chapter 3: The Data Model The Importance of the Core Data Model The Core Data Model Editor The Entity Entity Examples Did Someone Say SQL Tables? Adding a New Entity Attributes Attribute Types Number String, Boolean, and Date URI, UUID, and Binary Data Transformable Generated Classes How Is Your Data Model Really Created What Is NSEntityDescription? Welcome, NSManagedObject Access and Save Data Managed Properties Generated Classes The Data Model Inspector Class Definition Manual/None Category/Extension Attributes Inspector Optional Transient Default Value Use Scalar Type More Settings Summary Chapter 4: Relationships Some Theory First One-to-Many Many-to-Many One-to-One Relationships in SQL Tables Back to Xcode Creating Our First Relationship Configure Our Relationship Relationship Type Delete Rule Nullify Cascade Deny Arrangement (Only for “To-Many” Relationships) Count (Again, Only for “To-Many” Relationships) Let’s Take a Breath Editor Style Let’s Return to Code Connecting Entities Together A Relationship to Itself Summary Chapter 5: Contexts What Are Contexts? The Concept Scratch Pad Creating a Context Manipulating Data Insert New Objects Fetching Objects fetchRequest() Method Add a Predicate Sorting Fetch Offset and Limit Considering Context Changes Fetch Objects by ID Delete Objects Predefined Fetch Requests More Predefined Fetch Request Configurations Use Predefined Fetch Requests Multiple Contexts Multiple Main Contexts Optimistic Locking Merge Conflict Errors Merge Conflict Policy NSErrorMergePolicy mergeByPropertyStoreTrump mergeByPropertyObjectTrump overwrite rollback Nested Managed Object Contexts What Are Child Contexts? Creating a Child Context Sync Between Child and Parent Summary Chapter 6: Fetching Data Meet NSPredicate (Again) Predicate Syntax AND/OR Compound Predicates Substitution Variables Working with Strings Equal Diacritic-Sensitive Comparison BEGINSWITH and ENDSWITH LIKE: Wildcard Searches CONTAINS MATCHES Numbers Key Path Collection Queries Hello, NSExpressionDescription Creating a New NSExpressionDescription Reusing Relationships To-One To-Many Aggregate Operators SUBQUERY IN Debugging Console Launch Arguments Playgrounds Add a Playground Let’s Play External Data Editor Summary Chapter 7: Implementation Boundaries and Separations Isolation Protocols Core Data Everywhere Network Objects Meet DTOs: Data Transfer Objects Creating DTOs Let’s Make It Dynamic Reflection Working with the UI Layer What Do We Want? Observing Data Changes Using Notifications How to Respond NSFetchedResultsController What Is It Exactly? Creating an NSFetchedResultsController Connect the NSFetchedResultsController Sections Respond to Changes beginUpdates() and endUpdates() Diffable Data Source Caching Delete the Cache Undo Why Do I Need It? Meet UndoManager Grouping Summary Chapter 8: Concurrency and Declarative Programming These Rules Are Written in Blood Contexts Are Not Thread-Safe Managed Objects Belong to Their Context Thread Writing in Private Context, Reading in Main Context Private Contexts Creating Performing Actions performAndWait() performBackgroundTask() Concurrency Patterns Parent/Child Strategy Private in Front What to Choose? Declarative Programming SwiftUI and Core Data Managed Object Support @FetchRequest Where Did My View Model Go? Import Data from the Web to Core Data Summary Chapter 9: Performance Faulting Batch Faulting Prefetching Deleting Improve Your Fetches Fetch Index Creating a Fetch Index Index Expressions Is a Fetch Index a Magic? Use One-to-One Relationships to Improve Performance Limit Your Results String Search Optimization Case-Sensitive Searching Improve Our Saving Batch Saving Ordering + Relationships Working with Instruments A Few Words About Instruments Opening Instruments About Core Data Instruments Core Data Saves Instrument Faults and Fetches Summary Chapter 10: Migrations Why Does Migration Happen? Data Model Changes Wait! Do You Really Need to Migrate? The Migration Three Steps Lightweight Migration Adding a New Model Version Modify the New Model Version Setting the Current Model Version Recompile and Open Our App Mapping NSMappingModel Enable Lightweight Migration Lightweight Migration Use Cases What About Renaming? Custom Mapping Migration First Step: Create a New Version and Lock It Create a Custom Mapping Model Map Song->Note to NoteObject Set the Source to Song Set Attribute Mapping Relationship Mapping Disable Automatically Inferring a Mapping Model Custom Migration Policy Splitting the Song Entity New Model Version and Mapping Model Create Our Migration Policy NSEntityMigrationPolicy Removing the Song Entity from the Model Version Summary Chapter 11: Building a Custom Store Type Custom Store: What Exactly Does It Mean? Why Do We Need That? Rely on Your Technology Cross-Platform Support Migrating from an Old Persistent Store Connect the Persistent Store Directly to a Web Service To Explore Another Stack Component NSIncrementalStore vs. NSAtomicStore How Do They Work? NSPersistentStore Registering the New Store NSAtomicStore Mapping the Data Loading All the Data More Insights What About Relationships? Adding a New Object Generate a New Reference ID Add a New Cache Node Saving Updating and Deleting NSIncrementalStore Loading the Store Execute Store Requests NSPersistentStoreRequest Fetching Saving ObjectID Faulting Web Services Summary Chapter 12: Core Data and the World Integrate with Spotlight A Few Words About Spotlight Core Data and Core Spotlight “Index in Spotlight” Persistent History Tracking Create a Core Spotlight Delegate Delete the Indexing Small Note About Privacy Share the Core Data Store with App Extensions App Container App Group Adding the App Group in Xcode Working with the New Container Folder Adding an Extension to an Existing App Why Not Use File Manager? Use the migratePersistentStore Method Core Data and CloudKit Set Up CloudKit The Integration Data Model Limitations NSPersistentCloudKitContainer Add CloudKit to an Existing App Store Location Make Existing Data Sync to iCloud Make Sure Persistent History Tracking Is Enabled Modify All Your Records Recreate Objects Summary Chapter 13: What’s Next? What Have We Learned Till Now? How to Start? Understand Your Needs Design Your Data Model Implementing Core Data Where to Go from Here Thanks Index
Donate to keep this site alive
How to download source code?
1. Go to: https://github.com/Apress
2. In the Find a repository… box, search the book title: Unleash Core Data: Fetching Data, Migrating, and Maintaining Persistent Stores
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.