美文网首页
12.10 __attribute__

12.10 __attribute__

作者: 哈库呐玛塔塔__ | 来源:发表于2020-05-15 00:33 被阅读0次

attribute((objc_subclassing_restricted))

标识被修饰的类不能被其他类继承。
通常写在.h文件中类的声明前 如:
attribute((objc_subclassing_restricted))
@interface TestObject : NSObject
@property (nonatomic, strong) NSObject *object;
@property (nonatomic, assign) NSInteger age;
@end

attribute((objc_requires_super ))

标识子类不许调用被修饰的方法super。
通常写在方法名后边 如:

@interface TestObject : NSObject

  • (void)testMethod attribute((objc_requires_super));
    @end

constructor / destructor

constructor代表main函数执行前可以做的一些操作,destructor是main之后可以做的一些事儿

image.png 如果有多个函数可以在constructor或者destructor后边添加括号内部写上数字作为优先级。
attribute((constructor(101)))
需要注意的是constructor中是优先级越低执行顺序越高,而destructor是优先级越高执行顺序越高。

overloadable

该属性允许定义多个同名但是参数不同类型或者个数的函数,类似于C++的函数重载。
attribute((overloadable)) void testMethod(int age) {}
attribute((overloadable)) void testMethod(NSString *name) {} attribute((overloadable)) void testMethod(BOOL gender) {}

objc_runtime_name

修改类的名字,并且不受命名规则限制

相关文章

网友评论

      本文标题:12.10 __attribute__

      本文链接:https://www.haomeiwen.com/subject/ltxgnhtx.html