Well, this is a bit problematic, as your code is wrong.
- You cannot declare instance variables in a category; using the latest Objective-C ABI, you can declare new instance variables inside the class extension (
@interface AClass () {//... ), but this is different from the category ( @interface AClass (ACategory) ). - Even if you could, the syntax for declaring an instance variable is that they are enclosed in braces after the
@interface string.
You can declare a property in a category, but you need to define its store without using a new instance variable (hence @dynamic instead of @synthesize ).
As for your actual question, you cannot call the initial implementation of the overridden method unless you use the swizzling method (facilitated by run-time functions like method_exchangeImplementations ). I do not recommend doing this at all; it is really scary and dangerous.
Update: Explanation of instance variables in class extensions
A class extension is similar to a category, but it is anonymous and must be placed in the .m file associated with the source class. It looks like this:
@interface SomeClass () {
Its implementation should be in the main @implementation block for your class. Thus:
@implementation SomeClass
Thus, extending a class is useful for storing variables and methods of a private instance from the public interface, but it will not help you add instance variables to a class that you do not control. There is no problem with overriding -dealloc , because you simply implement it, as usual, with any necessary memory management for the instance variables entered in the class extension.
Please note that this material only works with the latest 64-bit Objective-C ABI.
Jonathan sterling
source share