范型

294 阅读1分钟

1、定义

@interface ZFObject<__covariant ObjectType> : NSObject

- (void)addObject:(ObjectType)obj;

@end

__covariant 范型的子类型 转大类型(范型类的父类型)

__contravariant  大类型 转小类型

2、使用

ZFObject <NSObject *>*obj = [[ZFObject alloc]init];

NS_ASSUME_NONNULL_BEGIN  定义所有属性不可以为空

@interface ViewController ()

@property (nonatomic, strong, nullable) NSArray *dataSource;///<

//@property (nonatomic, strong, null_resettable) NSArray *datas;///< null_resettable set可以为空get 不可以为空 

@end

}

NS_ASSUME_NONNULL_END