OC3_协议关键字

时间:2023-03-09 19:59:16
OC3_协议关键字
//
// Student.h
// OC3_协议关键字
//
// Created by zhangxueming on 15/6/24.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h>
#import "Programmer.h" @interface Student : NSObject <Programmer> @end //
// Student.m
// OC3_协议关键字
//
// Created by zhangxueming on 15/6/24.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "Student.h" @implementation Student - (void)writeCode
{
NSLog(@"writing...");
} - (void)debugCode
{
NSLog(@"debug...");
} - (void)report
{
NSLog(@"report");
} @end
//
// Programmer.h
// OC3_协议关键字
//
// Created by zhangxueming on 15/6/24.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h> @protocol Programmer <NSObject> @required//必须实现的方法(缺省)
- (void)writeCode;
- (void)debugCode;
- (void)report; @optional//可选实现的方法
- (void)eat;
- (void)drink; @end
//
// main.m
// OC3_协议关键字
//
// Created by zhangxueming on 15/6/24.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h>
#import "Student.h" int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
//NSLog(@"Hello, World!");
Student *xiaoHua = [[Student alloc] init];
[xiaoHua report];
//[xiaoHua eat]; }
return ;
}