如何在Swift语言中实现反思?
我如何实例化一个类
[[NSClassFromString(@"Foo") alloc] init];
Run Code Online (Sandbox Code Playgroud) 我正在使用Swift与Typhoon和Cocoapods.一切顺利,直到我开始为我的Typhoon组件编写Integrationtest(根据Typhoon-Example-App测试).我想以与我在TyphoonFactory中的setUp() 方式相同的方式设置Test 方法AppDelegate.当我执行测试时,我总是得到一个
TyphoonBlockComponentFactory assertIsAssembly:] + 244:错误:MyApp.MyAssembly不是TyphoonAssembly的子类
Typhoon引发的错误(使用kindOfClass引擎盖下的方法.)相同的代码完美地工作AppDelegate,我无法弄清楚什么是错的.
为了验证这种行为,我实现了isKindOfClass检查booth类(参见下面的代码):
有人可以帮助我吗?多谢!
PodFile
inhibit_all_warnings!
target "MyApp" do
pod 'Typhoon', '2.1.0'
end
target "MyAppTests" do
pod 'Typhoon', '2.1.0'
end
Run Code Online (Sandbox Code Playgroud)
MyAssembly.swift
public class MyAssembly : TyphoonAssembly{
//Some definitions
}
Run Code Online (Sandbox Code Playgroud)
AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
…
var assembly : MyAssembly = MyAssembly()
//Always returns „true“
println("Is type of class: …Run Code Online (Sandbox Code Playgroud)