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