在接口中使用自定义类(目标 C)
我在界面中使用其他文件中的类时似乎遇到了一些麻烦。到目前为止我编写的方式是...
#import "NodeBase.h"
@interface Node : NSObject {
@public
Node * testnode;
}
其中 NodeBase 是一个头文件,用于处理其他类的导入,即
#import <Foundation/Foundation.h>
#import "Node.h"
#import "NodeConnection.h"
#import "NodeProperty.h"
我收到的错误是“解析问题:预期类型”,是否没有办法使用在这种情况下的课程?或者我的语法完全错误?
I seem to be having a bit of trouble with using classes from other files in my interface. The way I have written it so far is...
#import "NodeBase.h"
@interface Node : NSObject {
@public
Node * testnode;
}
where NodeBase is a header file that deals with the importing of the other classes i.e.
#import <Foundation/Foundation.h>
#import "Node.h"
#import "NodeConnection.h"
#import "NodeProperty.h"
The error I am getting is a "Parse Issue: Expected a type", is there no way to use a class in this context? Or have I got the syntax completely wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
NodeBase.h
导入Node.h
,您的Node.h
导入NodeBase.h
,创建一个循环参考。这是不允许的。您可以将所有内容放入
Node.h
中,然后只需在需要引用
Node*
的地方导入Node.h
即可。如果您想隐藏常见导入(例如
),您可以将它们放入SupportingFile/.pch
文件。Your
NodeBase.h
importsNode.h
, and yourNode.h
importsNodeBase.h
, creating a circular reference. This is not allowed.You can put everything in the
Node.h
Then you can simply import
Node.h
in places where you need to referenceNode*
.If you would like to hide common imports (e.g.
<Foundation/Foundation.h>
), you can put them intoSupportingFile/<Your-Project-Name>.pch
file.我用于消除循环依赖的方法是使用以下定义:
或者
仅添加此行定义接口或类并使其为编译器所知。实际的长定义可以跟在后面
,因此,请尝试在界面开头之前添加行
@interface Node;
The method I use for eliminating circular dependencies is using the following definitions:
or
just adding this line defines the interface or class and makes it known to the compiler. The actual long definition can follow after
So to the point, try adding the line
@interface Node;
before the beginning for your interface