我使用的XCode 4斜面加载文件
可有人请向我解释为什么当我写了一个单元测试(测试目标下),它无法找到我本地文件资源?我试图在单元测试中从NSBundle加载一个plist文件,但它不适用于单元测试目标。我试过把它扔在Test目标的Classes区域下面。
这里是我的代码:
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"urlMappings.plist"];
self.urlMappings = [NSDictionary dictionaryWithContentsOfFile:finalPath];
self.urlMappings是空的,即使urlMappings.plist在我的项目肯定存在着一些原因。这里是urlMappings.plist的来源,以证明它实际上是一本字典。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>%server%view.html</key>
<string>testHtml1.html</string>
</dict>
</plist>
任何想法? Thankyou
大厦关闭MikeSimmons的解决方案,我想出了下面的[Xcode中:TEST VS DEBUG预处理宏(http://stackoverflow.com/questions/6748087/xcode-test-vs-debug-preprocessor-macros/6763597 #6763597)。 – ma11hew28 2011-07-20 14:40:46