什么是Objective-C“类继承”? [英] What is an Objective-C "class continuation"?
问题描述
我无法完全明白我所看到的 Objective-C 类继承。是/这些...
- 在
@implementation
(.m
)文件? - 类类别的另一个名称? (不太可能, ASFAIK 类别不能有Ivars,期间)
- 类别额外资讯的另一个名称?
- 这是一个ARC特有的功能吗?
- 是否有特定的运行时或其他使用要求?
- 这是创建
@property
,以及?为什么会比设置@interface
文件/声明更好地设置ivars或属性? - 人们通过使用这样的特定术语来复杂化讨论 - 这似乎不存在于任何官方文档中(我可以找到)。
在Objective-C中,在头文件中定义东西(比如一个属性)而不是.m文件之间的区别?
讨论涉及这个问题,但只是云问题进一步 - 或至少失败
继承类是Apple称为 类扩展 。我已经看到铛叫他们继续类和gcc使用类继承。
在clang或gcc中编译:
@interface Foo:NSObject
@property int a;
@end
@interface Foo()
@property float a;
@end
...你会得到有趣的名字的错误。 p>
要回答您的问题的其余部分:
- 这样的事件的范围,生命周期和用例是什么?
扩展用于声明类的私有接口。您还可以使用它来重新声明(细化)公共属性声明。
- 特定于ARC的功能?
否。
- 是否有特定的运行时间或其他要求?
类扩展是一个编译时概念,不需要特殊的运行时。当然,他们需要一个支持它们的编译器(clang和gcc做在当前版本中)。
- 这是一个创建@property的合适地方吗?为什么会比设置@interface文件/声明更好地设置ivars或属性?
是的。
- 为什么人们使用这种特定的术语 - 似乎不存在于任何官方文档中(我可以找到)?
好吧,你知道...我也喜欢整个世界讲英语,但是暂时我很高兴我必须在学校学习它。
I can't quite figure out what I have seen referred to as an Objective-C "class continuation". Is this / are these…
- Ivar(s) declared in the
@implementation
(.m
) file? - Another name for a class category? (Unlikely, ASFAIK categories cannot have Ivars, period)
- Another name for a class extension?
- Something else?
That said...
- What is the scope, lifetime, and usage case for such a thing?
- Is this an ARC-specific "feature"?
- Are there specific runtime, or other requirements for their use?
- Is this an appropriate place to create an
@property
, as well? And why would this be a better place for setting ivars or properties than, say, the@interface
file / declaration? - Why do people complicate discussions by using such specific terminology - that seems NOT to exist in any official documentation (that I could find)?
In question In Objective-C what is the difference between defining something (say a property) in the header file as opposed to the .m file? the discussion touches on this issue, but sort of just clouds the issue further - or at least fails to provide a canonical reference / definition of the term… hence this question.
A continuation class is what Apple calls a class extension. I have seen clang call them "continuation class" and gcc uses "class continuation".
Compile this in clang or gcc:
@interface Foo : NSObject
@property int a;
@end
@interface Foo()
@property float a;
@end
... and you will get errors with the funny names.
To answer the rest of your question:
- What is the scope, lifetime, and usage case for such a thing?
Extensions are used to declare the private interface for a class. You can also use it to redeclare (refine) public property declarations.
- Is this an ARC-specific "feature"?
NO.
- Are there specific runtime, or other requirements for their use?
Class Extensions are a compile time concept and do not require a special runtime. Of course they do require a compiler that supports them (both clang and gcc do in current versions).
- Is this an appropriate place to create an @property, as well? And why would this be a better place for setting ivars or properties than, say, the @interface file / declaration?
YES. Because you might want to have private properties.
- Why do people complicate discussions by using such specific terminology - that seems NOT to exist in any official documentation (that I could find)?
Well, you know... I'd also prefer if the whole world spoke English, but for the time being I'm happy with the fact that I had to learn it in school.
这篇关于什么是Objective-C“类继承”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!