Core Data III
Core Data in a ViewModel.
Core Data III
Core Data in a ViewModel.
0
0
Checkbox to mark video as read
Mark as read

We explored the basics of Core Data in previous articles like this one, where the data was managed directly on the View. This is fine for managing simple data sets, but when it starts to get complicated it's recommended to manage that data from a ViewModel.

Data Model file and entity Person will be created in the same way as in the previous Core Data articles. Then we can create a Core Data manager called CoreData.

import CoreData

class CoreData {

    let container = NSPersistentContainer(name: "Model")

    static let shared = CoreData()

    private init() {
        container.loadPersistentStores { description, error in
            if let error = error {
                print("Core Data failed to load: \(error.localizedDescription)")
            }
        }
    }
}

Continue reading

Access to all the content with our plans.

Basic Plan

FREE

Start Now
  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • Question submissions
Monthly
Yearly

Plan logo

-

Unlimited access to the whole content

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • Question submissions

Stripe secure payment methods
Plan logo

-

Unlimited access to the whole content

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • Question submissions

Stripe secure payment methods
Plan logo

-

Solve your doubts at any level

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • 2 Question submissions per week

Stripe secure payment methods
Plan logo

-

Solve your doubts at any level

  • Junior level content
  • Senior level content
  • Expert level content
  • Extra content
  • 2 Question submissions per week

Stripe secure payment methods

0 Comments

Join the community to comment
Sign Up
I have an account
Be the first to comment

Accept Cookies

We use cookies to collect and analyze information on site performance and usage, in order to provide you with better service.

Check our Privacy Policy