简体   繁体   中英

What is an Objective-C “class continuation”?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM