Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the @dynamic directive in a Category implementation?

Tags:

objective-c

When I try to use the @dynamic directive in a category implementation, I get "@dynamic may not be specified in category without an interface".

Does anyone know if there's a proper way to use this directive in a category ?

like image 354
Xav Avatar asked Dec 15 '25 20:12

Xav


1 Answers

Define an interface for the category, just like you would with a class:

@interface NSObject (RetainProperty)
@property (nonatomic, readonly) BOOL moreThanOneRetain;
@end

@implementation NSObject (RetainProperty)
@dynamic moreThanOneRetain;

-(BOOL)moreThanOneRetain
{
    return (1 < [self retainCount]);
}
@end
like image 63
Felixyz Avatar answered Dec 17 '25 12:12

Felixyz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!