How to Preload and Import Existing Data


I’m looking for a simple example detailing how to import data (from JSON or anything else) into the Swift 5, iOS 14, Xcode 12 Core Data.

I’m trying to hack together something by copying/pasting from … but there are several pieces from this project that I think are beyond what I need. For example the persistence.swift file is a class rather than a struct, and there are changes to the @Main file which I don’t think are necessary for my case. If possible, I’d like to keep the boiler plate @Main file and the boiler plate persistence.swift file that are added when I select Core Data when I’m first creating the project.

Basically just importing data from:
let jsonURL = Bundle.main.url(forResource: “seed”, withExtension: “json”)!

and mapping to core data.

rather than using all the combine stuff in the linked example above.

Any pointers you can provide are greatly appreciated.

This topic was automatically closed after 166 days. New replies are no longer allowed.