什么是Objective-C“类继承”? [英] What is an Objective-C "class continuation"?

查看:137
本文介绍了什么是Objective-C“类继承”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法完全明白我所看到的 Objective-C 类继承。是/这些...


  1. @implementation .m )文件?

  2. 类类别的另一个名称? (不太可能, ASFAIK 类别不能有Ivars,期间)

  3. 类别额外资讯的另一个名称?





  1. 这是一个ARC特有的功能吗?

  2. 是否有特定的运行时或其他使用要求?

  3. 这是创建 @property ,以及?为什么会比设置 @interface 文件/声明更好地设置ivars或属性?

  4. 人们通过使用这样的特定术语来复杂化讨论 - 这似乎不存在于任何官方文档中(我可以找到)。

在Objective-C中,在头文件中定义东西(比如一个属性)而不是.m文件之间的区别?
讨论涉及这个问题,但只是云问题进一步 - 或至少失败

解决方案

继承类是Apple称为 类扩展 。我已经看到铛叫他们继续类和gcc使用类继承。



在clang或gcc中编译:

  @interface Foo:NSObject 
@property int a;
@end

@interface Foo()
@property float a;
@end

...你会得到有趣的名字的错误。 p>

要回答您的问题的其余部分:



  1. 这样的事件的范围,生命周期和用例是什么?


扩展用于声明类的私有接口。您还可以使用它来重新声明(细化)公共属性声明。



  1. 特定于ARC的功能?


否。



  1. 是否有特定的运行时间或其他要求?


类扩展是一个编译时概念,不需要特殊的运行时。当然,他们需要一个支持它们的编译器(clang和gcc做在当前版本中)。



  1. 这是一个创建@property的合适地方吗?为什么会比设置@interface文件/声明更好地设置ivars或属性?


是的。



  1. 为什么人们使用这种特定的术语 - 似乎不存在于任何官方文档中(我可以找到)?


好吧,你知道...我也喜欢整个世界讲英语,但是暂时我很高兴我必须在学校学习它。


I can't quite figure out what I have seen referred to as an Objective-C "class continuation". Is this / are these…

  1. Ivar(s) declared in the @implementation (.m) file?
  2. Another name for a class category? (Unlikely, ASFAIK categories cannot have Ivars, period)
  3. Another name for a class extension?
  4. Something else?

That said...

  1. What is the scope, lifetime, and usage case for such a thing?
  2. Is this an ARC-specific "feature"?
  3. Are there specific runtime, or other requirements for their use?
  4. 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?
  5. 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:

  1. 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.

  1. Is this an ARC-specific "feature"?

NO.

  1. 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).

  1. 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.

  1. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆