简体   繁体   English

子类/超类Objective-C

[英]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.

相关问题 如何在Objective-C中使用“超类的现有对象”初始化子类的对象 - how to initialize an object of subclass with an “existing object of superclass” in objective-C 强制子类在Objective-C中调用其超类方法 - Forcing a subclass to call its superclass method in Objective-C 超类如何在Objective-C的子类中触发动作? - How can a superclass trigger an action in a subclass in objective-c? 子类Objective-C类不与超类链接? - Subclass Objective-C class without linking with the superclass? 警告:不兼容的Objective-C类型将superClass分配给subClass - warning: incompatible Objective-C types assigning superClass to subClass 当对象可能是超类或子类时,Objective-C访问超类方法 - Objective-C Accessing Superclass Methods when Object Might be Superclass or Subclass Objective-C单例超类? - Objective-C Singleton Superclass? 实例化子类时,如何在超类中使用Objective-C工厂方法? - how can I use an Objective-C factory method in a superclass, when instantiating a subclass? 为什么我不能在子类中使用超类的属性(Objective-C) - Why can't I use the property of a superclass in a subclass (Objective-C) 为什么在Objective-C中使用超类指针调用子类方法? - Why can I call a subclass method with a superclass pointer in Objective-C?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM