问题描述
有没有办法在 Xcode 中重构混合 C++/Objective-C 代码?我正在使用 Cocos2D 和 Box2D 编写游戏,而 Box2D 是用 C++ 编写的,所以我编写的每个类都应该有 .mm 扩展名,因此当我尝试例如重命名变量,我收到类似Xcode 只能重构 C 和 Objective-C 代码"的消息.
Is there a way to refactor mixed C++/Objective-C code in Xcode ?? I am writing a game using Cocos2D and Box2D, and the Box2D is written on C++, so every class I write should have .mm extension and therefore when I try to e.g. rename the variable, I got a message like "Xcode can only refactor C and Objective-C code".
提前致谢!
推荐答案
Xcode 在重构方面非常有限,即使是普通的 Obj-C.它基本上是重命名,甚至不能在评论中重命名.如果它说它不能做某事,那么它可能不能.
Xcode is VERY limited with refactoring, even with plain Obj-C. It's basically renaming and it can't even rename in comments. If it says it can't do something, then it probably can't.
重命名的唯一方法是使用 find &替换
.请注意,Xcode 可以处理正则表达式,因此通常已经足够好了.
The only way to rename is using find & replace
. Note that Xcode can handle regular expressions so it is often good enough.
当然,问题在于 find &replace 不了解编程语言,有时会添加一些额外的替换或忘记替换某些内容,因此要格外小心.每次重构后都需要进行干净的构建,以检查所有内容是否正确重命名.
Of course, the problem is that find & replace doesn't know the programming language and sometimes can add some extra replace or forget to replace something, therefore be extra careful. Clean build is neccessary after every refactoring to check everything got renamed correctly.
您也可以使用命令行工具(例如 sed
)来实现相同的目的.
You can also use command line tools (e.g. sed
) to achieve the same.
这篇关于Xcode C++ 和 Objective-C 重构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!