Mac OSX Core Data App-将生产数据与调试数据分开 [英] Mac OSX Core Data App - keep Production data separate from debug data

查看:36
本文介绍了Mac OSX Core Data App-将生产数据与调试数据分开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Mac OSX Core Data业务应用程序.我的问题是我是通过Xcode在Debug模式下运行应用程序,还是运行自己的个人生产版本(来自Mac App Store),都使用相同的数据(即相同的沙箱区域).我需要能够在不影响生产副本的情况下使用Debug版本数据.是否可以使用项目设置更改调试沙箱的位置,或者至少更改数据位置?

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?

推荐答案

我通过更改在调试"模式下使用的目录,在代码中(特别是在AppDelegate.swift/applicationDocumentsDirectory中)分离了Live/Debug数据.

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.

我首先在Swift Compiler-Custom Flags下设置DEBUG和RELEASE符号:屏幕截图

I first set the DEBUG and RELEASE symbols here under Swift Compiler - Custom Flags: screenshot

然后在代码中,我根据DEBUG符号返回数据目录:

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

这篇关于Mac OSX Core Data App-将生产数据与调试数据分开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆