Mock account preview service
In SwiftUI, I love having previews, but they will not always work. We can use previews with Core Data. Setting up a mock preview service helps me to create Core Data objects and use them in preview. We need a checking account, a credit account, and at least two cards in this app. We only need two cards, one for each type of account, for now.
Open MockAccountPreviewService
inside the Models
folder and add the following code:
struct MockAccountPreviewService { static let moc = CoreDataManager.shared.context // Checking Account // Credit Account // Visa Card // AMEX Card }
We have our struct
and an instance of the managed object context, which we have named moc
. We will pass moc
to each item we need to create with Core Data.
Next, let's add the cards as we will need them for our accounts. Add the following after the // Visa Card
comment:
static var visaCard: Card = { let card = Card(context: moc) ...