OC里__kindof和__typeof有什么区别?
比如为什么
__weak --typeof(self)weakSelf = self;
用的是__typeof?;
而
- (void)configCell:(__kindof UITableViewCell*)cell atIndexPath:(NSIndexPath*)indexPath
用的是__kindof?
首先__kindof
:规定参数为UITableViewCell这个类或者其子类。比如说一个NSArray<UIView *>*
,如果不加__kindof
,这个数组只能有UIView,即便是其子类也不行。而加了的话,传入UIImageView或者UIButton之类的不会有问题。
而__typeof
会返回对应的类型。
The __typeof operator lets you get the System::Type type of a type that you specify. __typeof can also be used to return a value of System::Type in a custom attribute block.
补充两个链接
__kindof
__typeof