You need to make sure your budget class calls NSCoder
, and then the NSCoder initWithCoder:
and NSCoder decodeWithCoder:
. Otherwise, writeToFile:
will not work for you NSObject
.
But I was distracted. The answer to the original question should be as follows.
In your .h
file, you need to do the following.
@interface WhateverClassName : UIViewController { NSMutableArray *anArray; } @property(nonatomic, retain) NSMutableArray *anArray; @end
Then you need to make sure that you are @synthesize
NSMutableArray
so that you don't have any fancy warnings. This is done immediately after the @implementation
line in your .m
file.
Then, within the function that you want to allocate to memory, simply follow these steps.
anArray = [[NSMutableArray alloc] initWithObjects:nil];
Now this is a global
variable. It is global
in the sense that it can be used from any function and is not limited to being used in one function.
source share