• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Programatically set file URL of Core Data Document?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Programatically set file URL of Core Data Document?


  • Subject: Programatically set file URL of Core Data Document?
  • From: Jerry Krinock <email@hidden>
  • Date: Mon, 18 May 2009 12:33:20 -0700

I'm trying to programatically set the initial file url (path, filename) of an Core Data NSPersistentDocument, or if that is not possible, at least populate the Save panel with an initial filename.

At first, I was using -[NSDocument saveToURL:ofType:forSaveOperation:error:]. That worked fine until I switched from XML to SQLite store, whereupon I began getting "Could not merge changes" errors when saving [1].

Then, I tried to implement -prepareSavePanel: and in there to setFileURL: if it is found to be nil, as it is for a new document. But this results in a "nil is not a valid persistent store" being logged upon saving. [1]

Then, I tried using -[NSPersistentStoreCoordinator migratePersistentStore:toURL:options:withType:error:]. But this results in a crash upon saving, in -[NSDocument _saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo :]. [2]

Then, I tried removing the old persistent store with removePersistentStore:error: and adding a new one with addPersistentStoreWithType:configuration:nilURL:options:error:. But that results upon saving in errors such as "The NSManagedObject with ID:0x16d22cb0 <x-coredata://...> has been invalidated".

For brevity, I have omitted my arguments for and against each of the four approaches.

What is the correct approach to do programatically set the file URL of an NSPersistentDocument? Or if someone could rule out one or more of my four approaches, at least I would know which to not waste any time beating on :)

Thank you,

Jerry Krinock


[1] In the error's userInfo, in the the 'conflictList', I see that the newVersion is 0 but the old version is 1. That seems kind of weird but I'm just guessing...


conflictList:
(
{
cachedRow = {
configureAutomatically = 1;
defaultSortable = 1;
displaysFolders = 1;
doExportAfterSave = <null>;
doFindDupesAfterOpen = <null>;
doImportAfterOpen = <null>;
doOpenAfterLaunch = <null>;
doSortAfterOpen = <null>;
filterIgnoredPrefixes = 0;
hasBar = 0;
hasMenu = 0;
hasOhared = 0;
hasUnfiled = 0;
ignoreDisparateDupes = 0;
lastDupesDone = <null>;
lastDupesMaybeMore = <null>;
lastSortDone = <null>;
lastSortMaybeNot = <null>;
lastTouched = <null>;
lastVerifyDone = <null>;
lastVerifyMaybeNot = <null>;
notes = "Document created 2009 May 17 17:40 by jk.";
rootLeavesOk = 0;
rootNotchesOk = 0;
rootSoftainersOk = 0;
rootSortable = 127;
satchAll1 = 1;
satchAll2 = 1;
softainersAnyRootIndex = 0;
sortBy = 0;
sortFoldersAt = 0;
tagDelimiter = 61441;
uuid = "F1724F28-C8A1-4F92-9334-C1C48721868B";
visitor = visitDB;
};
databaseRow = {
};
newVersion = 0;
object = Bookshig 0x2800630 owned by Bookshelf 0x165ecac0 "untitled_5.bkmslf";
oldVersion = 1;
}
)


[2] Actually, the crash occurs in the next call, -[NSDocument _willPresentSavingError:forOperation:url:]. I suppose that the 'url' parameter may be invalid.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Capturing key events in a menu
  • Next by Date: Re: Take over function keys
  • Previous by thread: Re: Capturing key events in a menu
  • Next by thread: re: Programatically set file URL of Core Data Document?
  • Index(es):
    • Date
    • Thread