开发者

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

开发者 https://www.devze.com 2023-01-09 20:47 出处:网络
When I try to use开发者_JAVA技巧 the @dynamic directive in a category implementation, I get \"@dynamic may not be specified in category without an interface\".

When I try to use开发者_JAVA技巧 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 ?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消