在 Objective-C 中重新定义为另一种符号 [英] Redefinition of as a different kind of symbol in Objective-C

查看:61
本文介绍了在 Objective-C 中重新定义为另一种符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个 WayPoint 类.但在某些时候,我们决定将类重命名为 Placemark.但是,我们并不是真的想更改类的名称,因为这会导致对现有代码进行大量修改.因此,我在头文件的底部添加了一行 typedef 并开始在任何新代码中愉快地使用 Placemark .

We have a class WayPoint. But at some point, we decided to rename the class to Placemark. However, we don't really want to change the name of the class because it will result in a lot of modification of the existing code. Therefore, I added one line of typedef at the bottom of the header file and start using Placemark in any new code happily ever since.

@interface WayPoint : _WayPoint
@end
typedef WayPoint Placemark;

但是还有一件事我不明白.如果我尝试在其他一些头文件中使用前向定义.我只能用:

But there is still one thing that I don't understand. If I try to use the forward definition in some other header file. I can only used:

@class WayPoint;

如果我使用:

@class Placemark;

我会收到错误信息:

将地标"重新定义为另一种符号

Redefinition of 'Placemark' as a different kind of symbol

为什么?

推荐答案

不知道为什么不能使用 Xcode 的重构功能(简单重命名可以快速轻松地完成).但是如果你真的想这样做,你可以使用比 typedef 更好的东西:

Not sure why can't you use Xcode's refactoring features (Simple Rename does it fast and easy). But if you really want to do this you may use something better then typedef:

@compatibility_alias Placemark WayPoint

这篇关于在 Objective-C 中重新定义为另一种符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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