Core Data: Fundamentals

Jul 19 2022 · Swift 5.5, iOS 15.4, Xcode 13.3.1

Part 2: Saving Launches

12. Inserting Data Into the Context

Episode complete

Play next episode

About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 11. Creating Managed Objects Next episode: 13. Conclusion

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In the last video you created a managed object subclass for the RocketLaunch entity. Now you can use this class to create instances of a RocketLaunch for users to save. If you build and run the app, you’ll see a new rocket launch button at the bottom of the screen. When you tap on that you’re presented with a modal view to enter details about the rocket launch.

let persistenceController = PersistenceController.shared
	.environment(\.managedObjectContext, persistenceController.container.viewContext)
import CoreData
@Environment(\.managedObjectContext) var viewContext
let launch = RocketLaunch(context: self.viewContext) =
launch.notes = self.notes
launch.launchDate = self.launchDate
launch.isViewed = self.isViewed
launch.launchpad = self.launchpad
do {
catch {
  let nserror = error as NSError
  fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
  static func createWith(
    name: String,
    notes: String,
    launchDate: Date,
    isViewed: Bool,
    launchpad: String,
    using managedObjectContext: NSManagedObjectContext
  ) {}
	notes: self.notes,
	launchDate: self.launchDate,
	isViewed: false,
	launchpad: self.launchpad,
  using: self.viewContext)
A really cool launch
My back yard
I really hope this takes off!