编程技术记录

世界你好!

在做swift和OC混编时,学到的.
使用attribute指令,将Objective-C的类标记为objc_subclassing_restricted。


//标记ClassA不能被继承
__attribute__((objc_subclassing_restricted))
@interface ClassA : NSObject
@end

@implementation ClassA
@end

//下面代码会报错
//error: Cannot subclass a class that was declared with the 'objc_subclassing_restricted' attribute
@interface ClassB: ClassA
@end

@implementation ClassB
@end

© Beli. All Rights Reserved.