在 Objective C 中,每当我需要访问测试包时,我都会调用
[NSBundle bundleForClass:[ClassInTestTarget class]];
bundleForClass
在Swift中不可用,那么我该如何访问测试包?
我需要这样做的原因是为了对我正在工作的框架编写测试,我必须使用内存中的core data stack。最初,所有资源都包含在主目标和测试目标中,但随后我将所有这些测试辅助程序移动到仅限于测试目标,现在下面的代码返回nil,导致我的所有测试失败。
let modelURL = NSBundle.mainBundle().URLForResource("Model", withExtension: "momd")
/Applications/Xcode.app/Contents/Developer/usr/bin
路径的捆绑包。有什么想法为什么会这样,或者如何修复它? - Ian BytchekBundle(for: ClassInTestTarget.self)
会导致错误Use of unresolved identifier 'ClassInTestTarget'
。 - Reinhard Männer