Search code examples
objective-cpropertiesobjective-c-categoryclass-extensions

Accessing a property defined in the class extension from a category, in Objective-C: is it possible?


One of my classes MyClass is very big and I want to split it into several categories MyClass(A), MyClass(B), ... . My problem is that some of the methods of MyClass+A make use of a @property defined in the class extension MyClass().

  • Can I access it from the category, and if yes: how?

  • If no, is there another way to proceed?


Solution

  • Can I access it from the category, and if yes: how?

    Yes. Either:

    1. define the continuation category in a different .h file (xxx_Private.h) and include that into your implementation files
    2. Or, redefine the method in a category interface at the top of the implementation file.

    Option 1 is the better solution.