![](/img/trans.png)
[英]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.