KEMBAR78
Swiftdata by Example Toc | PDF | Databases | Information Technology Management
0% found this document useful (0 votes)
60 views3 pages

Swiftdata by Example Toc

The document is a comprehensive guide on SwiftData, detailing its features, comparisons with Core Data, and practical applications. It covers building projects, defining data models, managing relationships, and handling data operations, as well as migration strategies and architecture considerations. Additionally, it addresses common problems and solutions related to SwiftData usage.

Uploaded by

Mohit Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views3 pages

Swiftdata by Example Toc

The document is a comprehensive guide on SwiftData, detailing its features, comparisons with Core Data, and practical applications. It covers building projects, defining data models, managing relationships, and handling data operations, as well as migration strategies and architecture considerations. Additionally, it addresses common problems and solutions related to SwiftData usage.

Uploaded by

Mohit Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Contents

Introduction 6
What is SwiftData?
SwiftData vs Core Data
Should you learn SwiftData, Core Data, or both?
Frequently asked questions about SwiftData
How to follow this quick start guide
Migrating from Core Data to SwiftData
Dedication

Building a complete project 17


SwiftData tutorial: Building a complete project
Defining a data model with SwiftData
Querying SwiftData objects in SwiftUI
Creating, editing, and deleting model objects
Sorting query results
Filtering the results from a SwiftData query
Working with relationships
Wrap up: our SwiftData project is complete

Containers and context 42


What's the difference between ModelContainer, ModelContext, and
ModelConfiguration?
How to configure a custom ModelContainer using ModelConfiguration
How to add multiple configurations to a ModelContainer
How to change SwiftData’s underlying storage filename
When does SwiftData autosave data?
How to enable or disable autosave for a ModelContext

Defining your data model 54


How to define SwiftData models using the @Model macro
Why are SwiftData models created as classes?
What kind of data can be a SwiftData property?
Using structs and enums in SwiftData models
How to make unique attributes in a SwiftData model
How to make transient attributes in a SwiftData model
How to store SwiftData attributes in an external file

www.hackingwithswift.com 3
How to index SwiftData objects in Spotlight
How to encrypt SwiftData
How to create derived attributes with SwiftData
How to index SwiftData properties for faster searching

Creating relationships 76
Inferred vs explicit relationships
How to create one-to-one relationships
How to create one-to-many relationships
How to create many-to-many relationships
How to create cascade deletes using relationships
How to add minimum and maximum constraints to relationships

Working with data 97


How to find a SwiftData by its identifier
How to save a SwiftData object
How to delete a SwiftData object
How to create a custom FetchDescriptor
How to filter SwiftData results with predicates
How to sort SwiftData queries using key paths or SortDescriptor
How to get natural string sorting for SwiftData queries
How to count results without loading them
How to delete all instances of a particular model
How to create a background context
How to add support for undo and redo
How to completely reset a SwiftData ModelContainer
How to enumerate a fetch request to handle lots of data efficiently
How to merge two model contexts
How to make SwiftData models conform to Codable
How to rollback changes without saving

Handling migration 138


Lightweight vs complex migrations
How to rename properties without losing data
How to create a complex migration using VersionedSchema

Building with SwiftData 148


How to connect SwiftData to SwiftUI
How to use @Query to read SwiftData objects from SwiftUI
How to dynamically change a query's sort order or predicate
What's the difference between @Bindable and @Binding?

4 www.hackingwithswift.com
What's the difference between @Bindable and @Binding?
How to animate changes to SwiftData queries
How to use SwiftData in SwiftUI previews
How SwiftUI tracks changes in SwiftData objects
How to use SwiftData with UIKit
How to migrate an app from Core Data to SwiftData
How to make Core Data and SwiftData coexist in the same app
How to create a document-based app with SwiftData
How to sync SwiftData with iCloud
How to stop SwiftData syncing with CloudKit
How to access a SwiftData container from widgets

Architecture 186
How to use MVVM to separate SwiftData from your views
How to discard changes to a SwiftData object
How to pre-populate an app with an existing SwiftData database
How to pre-load an app with JSON
How to transfer an object between a background context and the main context
How SwiftData works with Swift concurrency
How to batch insert large amounts of data efficiently
How to write unit tests for your SwiftData code
How to write UI tests for your SwiftData code
How to optimize the performance of your SwiftData apps
How to use SwiftData to store singletons

Solving problems 238


How to read the list of objects that have been inserted, edited, or deleted
How to check whether a SwiftData model object has been deleted
Using launch arguments to debug SwiftData and Core Data
How to read the contents of a SwiftData database store
Common SwiftData errors and their solutions

Afterword 253

www.hackingwithswift.com 5

You might also like