[英]Creating a category for classes that implement a specific protocol in Objective-C?
[英]Declare conformance to objective-c protocol with a category and implement it with another category
clang报告说Test1(FooBar)
没有实现foo
或bar
,尽管foo在Test1(Foo)
中实现,而bar
在Test1
中实现。 由于Test1(Foo)
的@interface
存在于Test1(FooBar)
之上,因此clang应该看到Test1(Foo)
实现了foo
并且不应该要求我在Test1(FooBar)
实现它。 由于Test1
实现了bar
,因此clang不应该要求我在Test1(FooBar)
实现它。
@interface Test1 : NSObject
- (void) bar;
@end
@interface Test1(Foo)
- (void) foo;
@end
@protocol FooBar <NSObject>
- (void) foo;
- (void) bar;
@end
@interface Test1(FooBar)<FooBar>
@end
@implementation Test1(Foo)
- (void) foo {
}
@end
@implementation Test1(FooBar)
@end
我的理解是这一行:
@interface Test1(FooBar)<FooBar>
可以用简单的英语被解释为“上类测试1 类别 FooBar的应实施协议FooBar的”。 换句话说,该协议适用于类别,而不是类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.