Mac OSX Core Data App - keep Production data separate from debug data

六眼飞鱼酱① 提交于 2021-02-08 10:17:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!