协议可以在Objective-C中继承吗? [英] Are protocols inheritable in Objective-C?

查看:66
本文介绍了协议可以在Objective-C中继承吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在框架目录的某些头文件中看到了这一点:

I saw this in some header file in the framework directory:

@interface NSCharacterSet : NSObject <NSCopying, NSMutableCopying, NSCoding>

@end

@interface NSMutableCharacterSet : NSCharacterSet <NSCopying, NSMutableCopying>

@end

我认为协议是可继承的。那,则无需在 NSMutableCharacterSet:NSCharacterSet 之后再次键入< NSCopying,NSMutableCopying> 。和NSMutableCharacterSet还符合NSCoding协议,对吗?

I thought protocols were inheritable.If I am right about that,There is no need to type <NSCopying, NSMutableCopying> again after "NSMutableCharacterSet : NSCharacterSet".And NSMutableCharacterSet also conforms to NSCoding protocol, right?

然后为什么苹果要再次键入?我犯错了吗?

Than why is Apple typing that again?Am I making mistake?

推荐答案

是的。子类也将采用相同的协议。

Yes. Subclasses will adopt the same protocols as well.

Apple再次键入该文本的原因是NSMutableCharacterSet已覆盖 -copyWithZone: -mutableCopyWithZone:

The reason Apple typing that again is because NSMutableCharacterSet has overridden -copyWithZone: and -mutableCopyWithZone:.

这篇关于协议可以在Objective-C中继承吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆