Originally posted by everdream:
<STRONG>I have a program where I need to use arrayWithContentsOfFile in awakeFromNib. I also need to use writeToFile:atomically: in an action. My problem is that if I declare the mutable array in the .h file it won't let me use arrayWithContentsOfFile to initialize it. I just need a mutable array available to any function in a .m file.</STRONG>
NSMutableArray is a subclass of NSArray, and implements all methods from NSArray. Therefor you should have no problem calling:
myMutableArray = [NSMutableArray arrayWithContentsOfFile:...];
to get a mutable array back. What problem is preventing you from this? Is the compiler complaining about something? (it shouldn't)
Just remember that arrayWithContentsOfFile: returns an autoreleased object, so if you need to access outside the awakeFromNib method you need to call [[NSMutableArray arrayWithContentsOfFile:...] retain] or
[[NSMutableArray alloc] initWithContentsOfFile:...]. Remember to call [myMutableArray release] somewhere to avoid leaking the memory. The dealloc method is probably a good place for this. Hope this helps!
/Tobias