反射创建对象和方法
@H_404_4@class TestSW: NSObject {
override required init() {
print("init333333")
}
@H_404_4@@objc @H_404_4@func test(){
print("000")
}
@H_404_4@@objc @H_404_4@func test11(from:String){
print("111")
}
}
反射方法:
//反射创建对象
@H_404_4@let module = Bundle.main.infoDictionary!["CFBundleExecutable"] @H_404_4@as! String
@H_404_4@let sw = NSClassFromString(module + ".TestSW") @H_404_4@as! TestSW.Type;
@H_404_4@let testSWModel = sw.init() //必须含有init方法
//被反射的方法需要在方法前面添加 @objc 修饰,可用以下方法反射
@H_404_4@let methodSelector = NSSelectorFromString("test")
// let methodSelector = #selector(TestSW.test11(from:))
// let methodSelector = NSSelectorFromString("test11From:" )
testSWModel.perform(methodSelector)