使用命令行工具時,我試圖檢索存儲在名爲words.txt的文件中的單詞列表的路徑。該文件被添加到項目中,包含在項目的目標成員中,並選擇在目標的「複製文件」構建階段進行復制。 裏面Main.swift驗證碼:pathForResource在Mac OS X控制檯應用程序中返回nil
if let path = NSBundle.mainBundle().pathForResource("words", ofType: "txt") {
println("Path is \(path)")
} else {
println("Could not find path")
}
打印 「找不到路徑」。 mainBundle()類是否可以訪問正確的包?有關爲什麼pathForResource函數返回nil的任何想法?
嘿它非凡非常感謝你 – ashokdy