NSPersistentDocument

Discussion in 'Mac Programming' started by MrFusion, Mar 3, 2016.

  1. MrFusion, Mar 3, 2016
    Last edited by a moderator: Apr 4, 2016

    MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #1
    Is there any uptodate guide, article, sample code on NSPersistentDocument?

    I have multiple nsmanagedobject contexts and so I need to overwrite the read and write functions of NSPersistentDocument. Things have changed substantially in the last few years and it's not clear when steps have to be taken in the various functions.
    Code:
    func readFromURL(absoluteURL: NSURL, ofType typeName: FileType) throws
    func writeToURL(absoluteURL: NSURL, ofType typeName: FileType, forSaveOperation saveOperation: NSSaveOperationType, originalContentsURL absoluteOriginalContentsURL: NSURL?) throws
    func revertToContentsOfURL(url: NSURL, ofType typeName: String) throws
    
    The revertToContentsOfURL is most puzzling. Are you supposed to remove and re-add the persistent store or just reset the context?

    Can a file just be moved by cocoa without affecting the persistent store (SQLite) and coordinators? The document file is basically the persistent store file, so I am worried the database is going to get yanked out from under me.
     
  2. flashy-cat macrumors regular

    flashy-cat

    Joined:
    Apr 8, 2007
    Location:
    UK

Share This Page