Objective-C categories: Can I add a property for a method not in my category? Objective-C categories: Can I add a property for a method not in my category? objective-c objective-c

Objective-C categories: Can I add a property for a method not in my category?


Here's the warning you're getting:

warning: property ‘foo’ requires method '-foo' to be defined - use @synthesize, @dynamic or provide a method implementation

To suppress this warning, have this in your implementation:

@dynamic foo;


If something's declared in your category's interface, its definition belongs in your category's implementation.


I wrote two articles on this, though the concept is slightly different from the question you're asking.

  1. Add properties to categories without touching the base class: http://compileyouidontevenknowyou.blogspot.com/2012/06/adding-properties-to-class-you-dont.html
  2. Access iVars from categories: http://compileyouidontevenknowyou.blogspot.com/2012/06/if-you-want-to-keep-everything-in-your.html

This is a LOT better than method swizzling, at least: way safer.