TLDR: Introduces Core Data as the main data store 💽
📙 I left some more explanations in comments in the code cause that's easier for future maintainers to see.
Adds Core Data for Tweet and Category CRUD
Core Data has been added and the supporting files can be found in the CoreData folder.
There are two entities.
CategoryEntity holds the categories and has a one to many relationship to the TweetEntity.
TweetEntity holds the tweets and has a many to one relationship to the CategoryEntity.
CoreData/StorageProvider.swift is used to initialize the NSPersistentContainer. It has preview variable which is used for the SwiftUI canvas/preview and a shared variable which is used all other times.
Migration from Amplify to Core Data
How a migration is performed:
On app launch, a check is done if the migration needs to happen.
All categories are fetched from AWS Amplify
For each category:
Translate the AWS Category to a CoreDataEntity
Fetch the AWS Tweets from the AWS Category
For each tweet, translate it to a TweetEntity and add it to the CategoryEntity tweets
Save to core data
How is a Migration determined:
The following conditions must both be true for a migration to run.
storageProvider.getAllCategories().isEmpty is true
The user default migrationToCoreDataRan is true
How I Tested
Run the application from dev branch, create a category and save some tweets
Run the application from jay/bugfix-data and see the categories look the same (migration ran)
Save some more tweets and the tweets persist through app load
Edit the category name and see it stays the same through app loads
Progress / Closed on issue #
What it Does
TLDR: Introduces Core Data as the main data store 💽
Adds Core Data for Tweet and Category CRUD
Core Data has been added and the supporting files can be found in the
CoreData
folder.There are two entities.
CategoryEntity
holds the categories and has a one to many relationship to theTweetEntity
.TweetEntity
holds the tweets and has a many to one relationship to theCategoryEntity
.CoreData/StorageProvider.swift
is used to initialize theNSPersistentContainer
. It haspreview
variable which is used for the SwiftUI canvas/preview and ashared
variable which is used all other times.Migration from Amplify to Core Data
How a migration is performed:
CoreDataEntity
TweetEntity
and add it to theCategoryEntity
tweetsHow is a Migration determined:
The following conditions must both be true for a migration to run.
storageProvider.getAllCategories().isEmpty
is truemigrationToCoreDataRan
is trueHow I Tested
dev
branch, create a category and save some tweetsjay/bugfix-data
and see the categories look the same (migration ran)