
大意如:
目前想到的办法:传 className 再进行判断绕开这个问题。
1 ai277014717 2018-09-20 09:24:14 +08:00 没看懂 CustomClass 到底是个什么类型 |
2 holonunu OP @ai277014717 指定类,比如 CustomViewController,但参数不是实例,是类 |
3 ai277014717 2018-09-20 10:02:14 +08:00 - (void)addClass:(Class) a{ [[a alloc] init]; } 写了一下编译完全没问题 |
4 holonunu OP @ai277014717 如果限定类型呢(比如把 Class 换成 UIViewController ),只能在函数内部判断? |
5 ai277014717 2018-09-20 10:27:42 +08:00 Class 可以限定协议 |
6 luciferovo909 2018-09-20 11:16:32 +08:00 类对象了解一下 |
7 holonunu OP @luciferovo909 不能作为参数吧 |
8 zjddp 2018-09-20 11:55:36 +08:00 运行时 |
9 chipmuck 2018-09-25 09:45:50 +08:00 __kindof UIViewController 看看 |
10 cheng4741 2018-09-26 14:43:36 +08:00 前段时间碰到过一样的问题,你可以 Class 后面加协议,如下 ``` - (void) addClass:(Class<CustomProtocol>)clazz; ``` 这样在你用到 addClass 方法的时候会有参数类型提示__unsafe_unretained Class<CustomProtocol> 但是编译器好像并不检查 clazz 是不是遵守 CustomProtocol,你随便传个其他类型也不会有警告 |