尽管导入了正确的标头,但使用自定义类时出现编译器错误
在我的 iOS 应用程序中,我有一个带有参数类型的接口,这些参数类型是我创建的继承自 NSObject
的类。 示例:
- (void) addTarget:(Target *)target;
在此接口中,我有 #include "Target.h"
,在该文件中定义了 Target
的接口。但是,每当我使用如上所述构建的任何类时,我都会遇到以下编译器错误:
“目标”之前应有“)”
但是,当我将参数的类型更改为内置类型时,它工作得很好。这是我在 Objective C 中的第一个项目。我是否缺少一些基本的东西?
In my iOS app, I have an interface with parameter types which are classes I've created that inherit from NSObject
.
Example:
- (void) addTarget:(Target *)target;
In this interface, I have #include "Target.h"
, in which file the interface for Target
is defined. However, whenever I use any classes I've built as above, I end up with this compiler error:
Expected ')' before 'Target'
However, when I change the type of the parameter to a built-in type, it works just fine. This is my first project in Objective C. Is there something fundamental I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您需要
#import "Target.h"
,或者声明您的自定义类的任何头文件。否则,编译器将不知道您在说什么。Yes, you need to
#import "Target.h"
, or whatever header file your custom classes are declared in. Otherwise, the compiler will have no idea what you're talking about.正如评论中提到的,删除循环依赖关系解决了问题。
As mentioned in the comments, removing the cyclic dependencies fixed the problem.