ios - Objective C: Reading text files -


i've done before, not working me now. i'm doing:

nsstring* path = [[nsbundle mainbundle] pathforresource:@"test"                                                   oftype:@"txt"]; nsstring* content = [nsstring stringwithcontentsoffile:path                                               encoding:nsutf8stringencoding                                                  error:null]; nslog(@"%@",path); 

and returns (null) every time when nslog path , content. can see i'm doing wrong?

content nil (which logs '(null)') if pass path can't open. issue relevant instance of nsbundle unable find test.txt within resources part of application bundle.

you should:

  1. check file in xcode project; and, if is,
  2. check it's included in 'copy bundle resources' phase underneath selected target (in project tree view on left in normal xcode window layout) and, if is,
  3. look inside generated application bundle (find product, right click, select 'reveal in finder', finder right click on app , select 'show package contents', file in there) make sure it's there.

if it's copied in relevant instance of nsbundle can't find strange afoot.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -