То же, что и @Arkady, но с Swift 2.0:
Сначала вызовите метод на mainBundle()
, чтобы помочь создать путь к ресурсу:
guard let path = NSBundle.mainBundle().pathForResource("MyFile", ofType: "txt") else {
NSLog("The path could not be created.")
return
}
Затем вызовитеметод defaultManager()
, чтобы проверить, существует ли файл:
if NSFileManager.defaultManager().fileExistsAtPath(path) {
NSLog("The file exists!")
} else {
NSLog("Better luck next time...")
}