协议实现多继承
协议实现多继承的话,只是简答的提供了接口,并灭有提供实现的方式。
A
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@protocol StuAProtocal <NSObject>
// 学生A 会游泳
- (void)swimming;
@end
@interface StudentA : NSObject
@end
NS_ASSUME_NONNULL_END
#import "StudentA.h"
@implementation StudentA
@end
B
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@protocol StuBProtocal <NSObject>
// 学生A 会游泳
- (void)running;
@end
@interface StudentB : NSObject
@end
NS_ASSUME_NONNULL_END
#import "StudentB.h"
@implementation StudentB
@end
C 遵守A 和 B 的协议
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface StudentC : NSObject
- (void)action;
@end
NS_ASSUME_NONNULL_END
#import "StudentC.h"
#import "StudentA.h"
#import "StudentB.h"
@interface StudentC()<StuBProtocal,StuAProtocal>
@end
@implementation StudentC
- (void)action{
[self swimming];
[self running];
}
- (void)running
{
}
- (void)swimming {
}
@end