Question

I'm trying to make a plugin for xcode where I want to write something to the h file from the m file. I can dynamically get the filepath from the class I'm currently writing code in, and by changing the .m to .h I'll have the filepath for the h file.

My question is, how do I write something to an .h file from xcode when I have the path?

Was it helpful?

Solution

NSString *path = @"your/path/tp/.h/file";
NSData *data = [NSData dataWithContentsOfFile:path];
//Get the contents of the file into the mutable string
NSMutableString *contents = [[NSMutableString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding];
//Make changes to your mutable string
[contents appendString:@"abc"];
//Write it back to the file
[contents writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];

OTHER TIPS

It´s not possible to do what you are asking. You can write only in files from your Documents Directory.

I don´t understand why do you need to write in a .h file for to change it. Maybe you could create subclasses from the same Class and you use one or other depending of your requirements

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top