Learn Courses My Dashboard

Developing for a Mac using Core Data

I’m writing a simple Address Book app for a mac using Core Data, using the Core Data lessons as a guide. I created a new XCode project with MacOS as the platform and included Core Data.

Here’s the generated code… (I changed the store name to AddressBook)

let container = NSPersistentContainer

init(inMemory: Bool = false) {
    container = NSPersistentContainer(name: "AddressBook")
    if inMemory {
        container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
    }
    container.loadPersistentStores(completionHandler: { (storeDescription, error) in
        if let error = error as NSError? {

This fails with a Cocoa error of 512.

This must mean that the file failed to be created, the error message does contain a full path name and I can’t find that path on my Mac.

Any Ideas? I Googled the error messages and descriptions of what I thought the error could be, but none seemed to make sense.

Use a colon : not equals =

Because you must say container is of type NSPersistentContainer, and later here, you are initializing the value

Also btw this group is mainly around iOS development. We most likely can’t help on MacOS apps

Hi @JimOlivi, I just want to say that I think it is awesome that you are working on Mac Apps. Mac Apps are on my list to learn as well and while there are a lot of people here at CWC+ that work on iOS, I am sure there is a lot of interest on Mac Apps as well.

Were you able to get your project working? Do you have journal that is documenting your progress? I would love to hear more about it.

I’m finding out that there is not much out there for tutorials for Mac apps. At least for free ones! The Apple-written tutorials build on their IOS/WatchOS apps. They have us build the “Landmarks” app for IOS, then we convert the app to a Mac app. I’m working through those at this time.

My issue is offline storage/persistent storage or Core Data. I can’t seem to get it to work by just compiling Chris’s example under a MacOS framework.

Are you planning on using cloudkit with core data or just core data?

I have very ambitious plans. After I get core data working, I’ll go to CloudKit. Then I’ll progress to an online database. I want to learn how to support an app on MacOS, IOS and WatchOS.

But, my overarching ambition is to learn about security and encryption.