0

Interesting problem...

I'm creating a Document based app and now need to convert my CoreData model so that it will use lightweight migration.

I've added a new model version and set it up as needed, and also selected v2 of my model as the current. Now I need to set up lightweight migration. I've done this before in another app, but in my previous app it wasn't a document based app (and it was also using an older version of Xcode.)

The problem I have now is: I did not set up the persistent store in this application, and thus there is no code in any of my files to persistent store... so I have no idea how or where to add the options dictionary so that lightweight migration will work.

I'm sure there is a simple solution, but I can't seem to find it.

Any ideas?

Greg Steiner
  • 647
  • 1
  • 9
  • 20
  • Never done it, but does [this](https://developer.apple.com/documentation/uikit/uimanageddocument/1622666-persistentstoreoptions) help at all? – pbasdf Feb 01 '18 at 22:01
  • Unfortunately no. That's the options dictionary I was referring to in my question. The issue is I have no idea how to pass it to the Persistent Store because I didn't create the Persistent Store. The last time I did this, I coded the setup of the Persistent Store but I didn't this time because, and I'm making an assumption here, XCODE sets it up automatically when you are creating a Document based application. – Greg Steiner Feb 01 '18 at 23:43
  • The link I provided is to a property of the UIManagedDocument - can't you set that property before opening the document, and it will then pass it to the persistent store coordinator? – pbasdf Feb 01 '18 at 23:54
  • Isn't UIManagedDocument iOS? This is in an OS X Application. – Greg Steiner Feb 02 '18 at 02:30
  • Update: the piece of the puzzle I was missing is that I had to Override the configurePersistentStoreCoordinator. Doh! – Greg Steiner Feb 02 '18 at 02:54
  • Sorry, I must read Tags more carefully. – pbasdf Feb 02 '18 at 08:44

1 Answers1

0

I found the solution here:

Core Data light migration on OS X

I just needed to override the function with my own version in my Document.swift file. Tested and working.

Greg Steiner
  • 647
  • 1
  • 9
  • 20