NSPersistentDocument retrieving metadata

I have a document-based Mac app that uses a storyboard. To store per-document settings, I use the metadata for the document's persistent store. I wrote a function to retrieve the metadata. The problem I am having is where to add the call to retrieve the metadata.


If I add the call in the NSPersistentDocument subclass's init method, the persistent store coordinator hasn't loaded yet. The coordinator's array of stores is empty at this point, preventing me from accessing the metadata. If I add the call to the NSPersistentDocument subclass's windowControllerDidLoadNib method, the function doesn't get called. I set a breakpoint that is never hit.


Where do I place the call to my function to retrieve the metadata so I can access the persistent store and its metadata?

Answered by szymczyk in 274136022

What worked for me was to place the call to retrieve the metadata inside makeWindowControllers.

Afaik, you don’t need to open the store to access it’s metadata. metadataForStore is a class function, and doesn’t need anything open. I use it to store some information that i want to access without opening, so call it before any open methods.

Accepted Answer

What worked for me was to place the call to retrieve the metadata inside makeWindowControllers.

NSPersistentDocument retrieving metadata
 
 
Q