2016-01-12 73 views
0

在SWIFT我怎樣才能得到我已經在Xcode路徑中的資源文件夾中的Xcode迅速

我的代碼複製到資源文件夾中的測試音頻文件的文件路徑的音頻文件提供了未找到文件。我正在尋找與NSSearchPathForDirectoriesInDomains正確的目錄?任何幫助非常感謝!

 let name = "test.wav" 
     let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString 
     let filePath = paths.stringByAppendingPathComponent(name) 
     let checkValidation = NSFileManager.defaultManager() 

     if (checkValidation.fileExistsAtPath(filePath)) { 
      print("found .wav") 
     } else { 
      print("file not found") 
     } 
+0

如果你在'paths'處設置斷點並且進入'checkValidation',那麼所有變量都有效嗎?如果您正在使用模擬器,請嘗試在Finder中導航到該路徑以查看該文件是否實際存在。 –

+0

生成的路徑不是Xcode資源的存儲位置。資源文件夾似乎在用戶/用戶/ appname/test.wav,但我不明白如何獲得路徑來挑選?當應用程序安裝在Xcode存儲文件的設備上時? – richc

回答

1

我剛剛發現這個工作。

let name = "test.wav" 
let soundPath = (NSBundle.mainBundle().resourcePath! as NSString).stringByAppendingPathComponent(name) 
let soundURL = NSURL.fileURLWithPath(soundPath) 
相關問題