NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

Core Data projects and Xcode

Forums > 100 Days of SwiftUI

I am revisting the Bookworm project and since last doing it XCode has been updated (12.3) and now produces a lot of additional boilerplate code and a default entity when Core Data is selected.

Any tips for what needs or can be deleted to proceed?

1      

I have the same question here...

   

Delete the Item entity in the model. Then comment out or delete the entire static preview var in the Persistence.swift file show here:

static var preview: PersistenceController = {
    let result = PersistenceController(inMemory: true)
    let viewContext = result.container.viewContext
    for _ in 0..<10 {
        let newItem = Item(context: viewContext)
        newItem.timestamp = Date()
    }
    do {
        try viewContext.save()
    } catch {
        // Replace this implementation with code to handle the error appropriately.
        // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
        let nsError = error as NSError
        fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
    }
    return result
}()

Finally, delete (or change the entity of) the @FetchRequest property in ContentView.

This is all that is required to "clean" the project from the boilerplate provided. You should be able to follow the steps in the Bookworm project now without issue.

   

For XCode 12.4 (Version 12.4 (12D4e)) using 'Swift 5'

I followed the suggestion of @nnorris7

I deleted the Item entity I removed the static preview var in Persistence.swift I set ContentView to this:

import SwiftUI
import CoreData

struct ContentView: View {
    var body: some View {
        Text("Hello")
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Now I started the tutorial... Code completion is not working and I got this error in the editor:

Cannot find type 'Student' in scope

Cleaned the build folder ('Cmd-Shift-K') and completely exited XCode

Restarted XCode and loaded 'Bookworm' Now, code completion works and I do not get the error.

   

Hacking with Swift is sponsored by Emerge

SPONSORED Emerge helps iOS devs write better, smaller apps by profiling binary size on each pull request and surfacing insights and suggestions. Companies using Emerge have reduced the size of their apps by up to 50% in just the first day. Built by a team with years of experience reducing app size at Airbnb.

Set up a demo!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.