Reputation: 187034
I want to use a category to make a method on the original class available as a property as well.
Class A:
@interface ClassA
- (NSString*)foo;
@end
Class A category
@interface ClassA (Properties)
- (void)someCategoryMethod;
@property (nonatomic, readonly) NSString *foo;
@end
Now when I do this, it seems to work (EDIT: Maybe it doesn't work, it doesn't complain but I am seeing strangeness), but it gives me warnings because I am not synthesizing the property in my category implementation. How do I tell the compiler everything is actually just fine since the original class synthesizes the property for me?
Upvotes: 29
Views: 25483
Reputation: 69757
I wrote two articles on this, though the concept is slightly different from the question you're asking.
This is a LOT better than method swizzling, at least: way safer.
Upvotes: 1
Reputation: 2030
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;
Upvotes: 34
Reputation: 2282
If something's declared in your category's interface, its definition belongs in your category's implementation.
Upvotes: 1