在Swift中使用 NSClassFromString

在Swift中使用 NSClassFromString
需要 工程名
+ .
+ string
1 | NSClassFromString(Bundle.main.object(forInfoDictionaryKey: "CFBundleName")! + "." + "CustomCell") |
每次写这些很麻烦,所以简单封装下
1 | public func GetClassFromString(_ classString: String) -> AnyClass? { |
以后就可以直接调用
1 | GetClassFromString("cellName") |
- Post title:在Swift中使用 NSClassFromString
- Post author:xxxixxxx
- Create time:2020-11-02 00:00:00
- Post link:https://xxxixxx.github.io/2020/11/02/100-在Swift中使用-NSClassFromString/
- Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
Comments