简体   繁体   中英

Declare conformance to objective-c protocol with a category and implement it with another category

clang reports that Test1(FooBar) doesn't implement foo or bar , despite foo being implemented in Test1(Foo) and bar being implemented in Test1 . Since Test1(Foo) 's @interface exists above Test1(FooBar) 's, clang should see that Test1(Foo) implements foo and shouldn't require me to implement it in Test1(FooBar) . Since Test1 implements bar , clang shouldn't require me to implement it in 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

My understanding is that this line:

@interface Test1(FooBar)<FooBar>

can be interpreted in plain english as "The category FooBar on class Test1 should implement protocol FooBar". In other words, the protocol applies to the category, not the class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM