[英]Subclass/ Superclass Objective-C
I'm learning Objective-C, noob question. 我正在学习Objective-C,菜鸟问题。
I'm working on a project in Xcode that requires multiple geometric object-types (square, triangle, etc). 我正在使用Xcode进行项目,该项目需要多种几何对象类型(正方形,三角形等)。 Each object file is made a subclass of the superclass "GraphicObject," for which there is a file as well obviously.
每个目标文件都是超类“ GraphicObject”的子类,显然也有一个文件。
My question is, when I create a new file to contain main code body, I cannot seem to make the new file recognize the subclasses of GraphicObject unless I do this: 我的问题是,当我创建一个包含主体代码主体的新文件时,除非执行以下操作,否则似乎无法使新文件识别GraphicObject的子类:
#import "GraphicObject.h" #import“ GraphicObject.h”
#import "Rectangle.h" #import“ Rectangle.h”
#import "Triangle.h" #import“ Triangle.h”
#import "Circle.h" #import“ Circle.h”
#import "Square.h" #import“ Square.h”
Is there a way for me to have the file refer to all subclasses of the GraphicObject class without explicitly adding them via the #import function? 有没有一种方法可以让我的文件引用GraphicObject类的所有子类,而无需通过#import函数显式地添加它们?
Thank you for reading. 感谢您的阅读。
I think you are confusing subclasses and dependencies. 我认为您在混淆子类和依赖项。 Just because
Rectangle
inherits from GraphicObject
, the class that uses just GraphicObject
has no idea what Rectangle
is. 仅仅因为
Rectangle
从继承GraphicObject
,使用刚刚类GraphicObject
不知道什么Rectangle
的。 You would need to use all of those #imports
. 您将需要使用所有这些
#imports
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.