What is an Objective-C “class continuation”?

前端 未结 1 1610
失恋的感觉
失恋的感觉 2020-12-18 03:34

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) declar
相关标签:
1条回答
  • 2020-12-18 04:03

    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.

    0 讨论(0)
提交回复
热议问题