#import <Foundation/Foundation.h>

@protocol Study <NSObject>
默认就是@required
- (void)test3;

表示必须实现的方法
// 虽然字面上说是必须实现,但是编译器并不强求某个类进行实现
@required
- (void)test;

- (void)test1;

// @optional表示可选(可实现\也可不实现)
@optional
- (void)test2;
@end


main.m文件
#import <Foundation/Foundation.h>
#import "Student.h"

Study;

int main(int argc, const char
{

@autoreleasepool {
Student *stu = [[[Student alloc] init] autorelease];

// OC是弱语法的,对类型要求不严格
// NSString *stu = [[[Student alloc] init] autorelease];
// [stu stringByAbbreviatingWithTildeInPath];

// conformsToProtocol:判断是否遵守了某个协议
if ([stu conformsToProtocol:@protocol(Study)]) {
NSLog(@"Student遵守了Study这个协议");
}

// respondsToSelector:判断是否实现了某个方法
if ( ![stu respondsToSelector:@selector(test)] ) {
NSLog(@"Student没有实现test这个方法");
}
}
return 0;
}