NSBundle.mainBundle().pathForResource returns nil

Do not include the .txt in the name parameter, pass it as the extension parameter.
From the documentation:

extension
The filename extension of the file to locate.
If you specify an empty string or nil, the extension is assumed not to exist and the file is the first file encountered that exactly matches name.

Swift3

let bundle = Bundle.main
let path = bundle.path(forResource: "Test", ofType: "txt")

Swift1 & Swift2

let bundle = NSBundle.mainBundle()
let path = self.bundle.pathForResource("Test", ofType: "txt")

Objective-C

NSBundle* bundle = [NSBundle mainBundle];
NSString* path = [bundle pathForResource:@"Test" ofType:@"txt"];

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)