Xcode:停止编译代码/函数行 [英] Xcode: stop lines of code / functions from compiling

查看:39
本文介绍了Xcode:停止编译代码/函数行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在几个项目中有共同的文件,我需要停止为项目A编译一些行和函数,同时应该为项目B编译.

I have common files in several projects and I need to stop from compiling some lines and functions for project A, meanwhile it should be compiled for project B.

我知道我可以使用预处理器.但是对我来说不方便.有什么方法可以阻止代码行在如下条件下编译?

I know that I can use preprocessor. But it's not convenient for me. Is there any way to stop lines of code from compiling with condition like below?

#if PhotosModuleSettings.type == .documents
... do not commpile
#endif

推荐答案

使用预处理器有什么不方便的地方?您可以在每个目标的构建设置中指定预处理器宏,也可以使用 .xcconfig 文件来指定它们.

What's not convenient about using the preprocessor? You can specify the preprocessor macros in build settings of each target, or you can use .xcconfig files to specify them.

不过,还有另一种简单的方法.将要有条件地编译为单独文件的行和函数分开.也许通过使用 Swift 扩展或子类化,或者只是单独的全局函数等等.无论如何.然后只需选择您希望将这些文件添加为成员资格的目标和/或项目.

There's another simple way to do it, however. Separate the lines and functions that you want to conditionally compile into separate files. Maybe by using Swift extensions or subclassing or just separate global functions, etc..whatever. Then just choose which target(s) and/or project(s) you want those files added as membership.

不过,根据您重构代码以实现此类文件分离的愿望,预处理器宏可能是更好的方法.

Depending on your desire to refactor your code to make such a file separation, the preprocessor macros may be the better way to go, though.

这篇关于Xcode:停止编译代码/函数行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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