2014-04-30 2 views

답변

1

예, 카테고리의 @interface 선언에 적절한 선언을 추가했다고 가정합니다. 당신은 스스로를 확인할 수 있습니다

@interface MyClass : NSObject 
@end 

@protocol Dummy <NSObject> 

-(void)dummyMethod; 

@end 

@interface MyClass (MyCategory) <Dummy> 

@end 

@implementation MyClass (MyCategory) 

+ (void)load { 
    BOOL conforms = [self conformsToProtocol:@protocol(Dummy)]; 
    NSLog(@"conforms to Dummy? %@", @(conforms)); 
} 

@end 

출력은 다음과 같습니다

는 더미에 적합? 1

당신은 documentation 얼마나 conformsToProtocol: 작품에 대한 설명을 읽을 수 있습니다

A class is said to “conform to” a protocol if it adopts the protocol or inherits from another class that adopts it. Protocols are adopted by listing them within angle brackets after the interface declaration. For example, here MyClass adopts the (fictitious) AffiliationRequests and Normalization protocols: 

@interface MyClass : NSObject <AffiliationRequests, Normalization> 
+0

우수함! 고맙습니다. – unmircea

관련 문제