Is it possible to read and write to a .h file with objective c? -


i'm trying make xcode plugin needs write .h file .m file. haven't been able find stackoverflow post answer on how this. i've tried code

nsdata *data = [nsdata datawithcontentsoffile:filepath]; nsstring *contents = [[nsstring alloc] initwithbytes:[data bytes] length:[data length] encoding:nsutf8stringencoding]; 

i've tried using stringwithcontentsoffile method, both return nil. because can't read .h file code or else i'm missing.

filepath , it's correct filepath, ftp client can read atleast file:///users/myusername/documents/code/macosdev/xcodeplugins/xcoderplugin/xcoderplugin/xcoderplugin.h

so question is, how read , write .h file? in advance.

edit requested, more code far i've gotten read/write part of plugin.

nsstring *filepath = path; nsdata *data = [nsdata datawithcontentsoffile:filepath]; nsstring *contents = [[nsstring alloc] initwithbytes:[data bytes] length:[data length] encoding:nsutf8stringencoding]; nserror *error; nsstring *contents1 = [nsstring stringwithcontentsoffile:filepath encoding:nsutf8stringencoding error:&error]; 

contents @"" because data nil , contents1 nil; error error

nserror * domain: @"nscocoaerrordomain" - code: 260 

in debugger, i'm not sure i'm using error thing correctly.

use "/users/myusername/documents/code/macosdev/xcodeplugins/xcoderplugin/xcoderplugin/xcoderplugin.h". dont use 'file://' prefix

following code reading , writing

nsstring *path = @"your/path/tp/.h/file"; nsdata *data = [nsdata datawithcontentsoffile:path]; //get contents of file mutable string nsmutablestring *contents = [[nsmutablestring alloc] initwithbytes:[data bytes] length:[data length] encoding:nsutf8stringencoding]; //make changes mutable string [contents appendstring:@"abc"]; //write file [contents writetofile:path atomically:yes encoding:nsutf8stringencoding error:nil]; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -