开发中,如果想指定初始化方法,不允许调用者乱用,可以用这两个宏:
NS_DESIGNATED_INITIALIZER,
NS_UNAVAILABLE
例如:
- (instancetype)initWithDelegate:(id<JXPagerViewDelegate>)delegate NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;
这时如果调用init方法,就会编译错误,环境Xcode10.2.1:
查看JXPagerView时发现,感谢开源库们!