文章目录 1、泛型 `Generics` 2、`__kindof` 类型限制 3、自定义泛型 4、协变 和 逆变 4.1、`__covariant`协变 4.2、`__contravariant`逆变 2、__kindof 类型限制 __kindof:类型限制 使用格式:__kindof XXClass 限制类型是:XXClass类型或XXXClass子类的实例 例1: // 返回值可以是:`UITableViewCell `或`UITableViewCell子类`的实例 - (__kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *) identifier; 例2: // 数组里可以是:`UIView`或`UIView子类`的实例 @property (nonatomic, readonly, copy) NSArray<__kindof
contextualActionWithStyle:UIContextualActionStyleNormal title:@"" handler:^(UIContextualAction * _Nonnull action, __kindof contextualActionWithStyle:UIContextualActionStyleDestructive title:@"" handler:^(UIContextualAction * _Nonnull action, __kindof
个人网站、项目部署、开发环境、游戏服务器、图床、渲染训练等免费搭建教程,多款云服务器20元起。
三、UITabBarController的属性和方法 //管理的viewController数组 @property(nullable, nonatomic,copy) NSArray<__kindof UIViewController *> *viewControllers; - (void)setViewControllers:(NSArray<__kindof UIViewController viewControllers animated:(BOOL)animated; //选中的ViewControlle @property(nullable, nonatomic, assign) __kindof moreNavigationController; //这个属性设置的是可以进行自定义排列顺序的视图控制器,如上面第二张图中的,默认是全部 @property(nullable, nonatomic, copy) NSArray<__kindof
addSubview:btn]; [[btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof addSubview:btn]; //监听点击事件 [[btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof addSubview:btn]; //监听点击事件 [[btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof
的方法外,还可以通过临时创建来做: //tableView在从复用池中取cell的时候,有如下两种方法 //使用这种方式如果复用池中无,是可以返回nil的,我们在临时创建即可 - (nullable __kindof dequeueReusableCellWithIdentifier:(NSString *)identifier; //6.0后使用如下的方法直接从注册的cell类获取创建,如果没有注册 会崩溃 - (__kindof forSupplementaryViewOfKind:(NSString *)kind withReuseIdentifier:(NSString *)identifier; //这两个方法是从复用池中取出cell或者头尾视图 - (__kindof dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath; - (__kindof UICollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath; //获取所有可见cell的数组 - (NSArray<__kindof
[[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof [[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof [UITapGestureRecognizer alloc] init]; [[tap rac_gestureSignal] subscribeNext:^(__kindof [UITapGestureRecognizer alloc] init]; [[tap rac_gestureSignal] subscribeNext:^(__kindof
assign) NSEntityDescription *superentity; //所有属性字典 @property (readonly, copy) NSDictionary<NSString *, __kindof NSPropertyDescription *> *propertiesByName; //所有属性数组 @property (strong) NSArray<__kindof NSPropertyDescription instancetype)initWithManagedObjectModel:(NSManagedObjectModel *)model; //添加一个持久化的数据接收对象 - (nullable __kindof
save; 示例 在doc路径下保存一个名为”arr.plist”的文件: 在cache路径下归档一个名为”myfile.plist”的文件: 读取 读取的方法目前提供了七个: - (nullable __kindof NSArray *)readArray; - (nullable __kindof NSDictionary *)readDictionary; - (nullable id)readArchivedPlist
//UITableView.h - (nullable __kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *) - (__kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath
UIViewController *visibleViewController; 3、 给导航控制器设置controller @property(nonatomic,copy) NSArray<__kindof *)popViewControllerAnimated:(BOOL)animated; (3)弹出到某个视图控制器 返回所有pop的controller - (nullable NSArray<__kindof *)viewController animated:(BOOL)animated; (4)直接pop到根视图控制器,返回所有被pop的controller - (nullable NSArray<__kindof
UIViewController *)popViewControllerAnimated:(BOOL)animated; //弹出到某个视图控制器 返回所有pop的controller - (nullable NSArray<__kindof *)viewController animated:(BOOL)animated; //直接pop到根视图控制器,返回所有被pop的controller - (nullable NSArray<__kindof //返回堆栈中所有的controller @property(nonatomic,copy) NSArray<__kindof UIViewController *> *viewControllers;
param success 请求成功的回调 * @param failure 请求失败的回调 * * @return 返回的对象可取消请求,调用cancel方法 */ + (__kindof param success 请求成功的回调 * @param failure 请求失败的回调 * * @return 返回的对象可取消请求,调用cancel方法 */ + (__kindof param success 请求成功的回调 * @param failure 请求失败的回调 * * @return 返回的对象可取消请求,调用cancel方法 */ + (__kindof param success 请求成功的回调 * @param failure 请求失败的回调 * * @return 返回的对象可取消请求,调用cancel方法 */ + (__kindof 下载失败的回调 * * @return 返回NSURLSessionDownloadTask实例,可用于暂停继续,暂停调用suspend方法,开始下载调用resume方法 */ + (__kindof
readonly) UIView *superview; 238 /** 获取所有子视图 */ 239 @property(nonatomic,readonly,copy) NSArray<__kindof view是否为子类 */ 278 - (BOOL)isDescendantOfView:(UIView *)view; 279 /** 通过tag获得对应的子视图 */ 280 - (nullable __kindof *)effect NS_AVAILABLE_IOS(7_0); 453 454 /** 所有添加的运动效果 */ 455 @property (copy, nonatomic) NSArray<__kindof UILayoutGuideSupport) 567 568 /** 此视图拥有布局向导对象的数组 */ 569 @property(nonatomic,readonly,copy) NSArray<__kindof UILayoutGuide (UIConstraintBasedLayoutDebugging) 625 626 /** 获得实体在不同方向上所有的布局约束 */ 627 - (NSArray<__kindof
UTF8String], sub, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } return sub; } -(void)registEvent:(__kindof -(void)registEvent:(__kindof DWEvent *)event onSubscriber:(DWEventSubscriber *)sub entity:(DWEventEntity -(void)receiveEvent:(__kindof DWEvent *)event { dispatch_semaphore_wait(self.sema, DISPATCH_TIME_FOREVER
//这里需要返回一个UICollectionViewLayoutAttributes数组里面就能存放fram信息 - (nullable NSArray<__kindof UICollectionViewLayoutAttributes heightAtt); return attrs; } 计算完了就可以让layoutAttributesForElementsInRect设置回布局了 - (nullable NSArray<__kindof
@property (nonatomic, readonly) NSArray<__kindof UITableViewCell *> *visibleCells; 这有一个疑问,当我们滑动屏幕时,屏幕上可见的
新增加的__kindof修饰符可以帮助我们解除这个烦恼。 但是以后就不需要了,我们在声明这个数组时加上一个__kindof修饰符: @property(nonnull,strong,nonatomic)NSMutableArray<__kindof UIView
UINavigationController *navigationController = self.navigationController; NSMutableArray<__kindof
."); __kindof 可以参考下面的连接 我就不多啰嗦了 Xcode 7新的特性Lightweight Generics 轻量级泛型与__kindof修饰符 NS_REQUIRES_SUPER
store.dispatch({ type: 'increment', payload: 2 }) // 1 + 2 console.log(store.getState()) // 3 isPlainObject 和 kindOf isPlainObject(action)) { // 是不是纯对象 throw new Error(`不是纯净的 Object,是一个类似 ${kindOf(action)} 的东西`) // 不是,是一个类似 XXX 的东西 } ... } 这里的 isPlainObject 和 kindOf 都是可以从 npm 里的 is-plain-object 和 kind-of 获得。 value.constructor.name : null } const kindOf = (value: any): string => { if (value === void 0) return isPlainObject(action)) { throw new Error(`不是纯净的 Object,是一个类似 ${kindOf(action)} 的东西`) }
扫码关注腾讯云开发者
领取腾讯云代金券