使用命令行工具时,我试图检索存储在名为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