我使用的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