UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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?

3      

I have the same question here...

2      

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.

3      

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.

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.