不同的代码/配置在发布&调试版本(Obj-C) [英] Different code / config in Release & Debug build (Obj-C)

查看:87
本文介绍了不同的代码/配置在发布&调试版本(Obj-C)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Objective C中编写了一个Cocoa应用程序,该应用程序与Web服务进行通信,我希望它在调试模式下连接到沙盒,在发布模式下连接到真实的Web服务。我需要的是改变一行代码,其中保存配置的对象被实例化(使用不同的init消息和不同的参数)。



您可以检查 #ifdef DEBUG

/ code>,但我建议你不要这样做。



Debug和Release版本之间有很大的区别。不同的编译器优化,不同的符号集等...



无论如何,你会发现自己处于一种情况,用于调试目的....和您的调试构建针对生产webservice,因为一些客户有一个问题,只能复制在发布模式。



所以, d建议用户默认。请参阅 NSUserDefaults



请注意,可以从命令行设置简单的用户默认值。



因此,你可以这样做:

  /path/to/Myapp.app/ Contents / Macos / Myapp -ServerMode Debug 


I'm writing a Cocoa app in Objective C that's communicating with a webservice and I want it to connect to a sandbox in debug mode and to the real webservice in release mode. All I need is to change on line of code where an object that holds the configuration gets instantiated (with a different init-message and different parameters).

So how would I swap a line of code for Release or Debug mode?

解决方案

You could check for #ifdef DEBUG, but I would recommend you don't do that.

There are a lots of differences between Debug and Release builds. Different compiler optimizations, different sets of symbols, etc...

Invariably, you are going to find yourself in a situation where you want to run the Release build against your sandbox for debugging purposes.... and your debug build against the production webservice because some customer has a problem that only reproduces in Release mode.

So, for that, I'd suggest a user default. See NSUserDefaults.

Note that simple user defaults can be set from the command line.

Thus, you could do something like:

/path/to/Myapp.app/Contents/Macos/Myapp -ServerMode Debug

这篇关于不同的代码/配置在发布&调试版本(Obj-C)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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