NSString -initWithContentOfFile error - Objective-C -


i'm trying load nsstring, content of file named names.txt, in directory of project. this, have following code :

    nserror *error = nil;     nsstring *names = [[nsstring alloc] initwithcontentsoffile:[[nsbundle mainbundle] pathforresource:@"names" oftype:@"txt"] encoding:nsasciistringencoding error:&error];     if (error != nil) {         [nsexception raise:@"error reading file :" format:@"%@",error];     } 

and i'm getting *** terminating app due uncaught exception 'error reading file :', reason: 'error domain=nscocoaerrordomain code=258 "the file name invalid."'. couldn't find other cases that. what's wrong code?

ensure names.txt file included under copy bundle resources region of xcode build phases window target.

in debugger, test valid bundle file with:

  ...   nsstring *file  = [[nsbundle mainbundle] pathforresource:@"names" oftype:@"txt"];   /* file ought not nil. nsassert (file) */   nsstring *names = [[nsstring alloc] initwithcontentsoffile: file                                                     encoding: nsasciistringencoding                                                        error: &error]; 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -