问题
I have created a Mac OSX Core Data business app. My issue is that whether I am running the app in Debug mode via Xcode or running my own personal production version (from the Mac App Store), both use the same data (i.e. the same sandbox area). I need to be able to mess with the Debug version data without affecting my production copy. Is there a Project Setting I can use to change the debug sandbox location, or at the very least change the data location?
回答1:
I have separated my Live/Debug data in the code, specifically in AppDelegate.swift/applicationDocumentsDirectory, by changing the directory used when in Debug mode.
I used the solution found here to differentiate between a DEBUG & RELEASE build.
I first set the DEBUG and RELEASE symbols here under Swift Compiler - Custom Flags: screenshot
Then in the code I return the data directory based on the DEBUG symbol:
#if DEBUG
return appSupportURL.URLByAppendingPathComponent("com.MyCompany.AppName.Debug")
#else
return appSupportURL.URLByAppendingPathComponent("com.MyCompany.AppName")
#endif
来源:https://stackoverflow.com/questions/35006916/mac-osx-core-data-app-keep-production-data-separate-from-debug-data