Okay, so I’m pretty new to xcode but I cannot find something specific to this issue anywhere. So I declare the array and instantiate it in the following files:
//xmlToUrl.h
#import <Foundation/Foundation.h>
@interface xmlToUrl : NSObject {
NSMutableArray *field;
NSMutableArray *name;
}
@property(nonatomic, retain)NSMutableArray *field;
@property(nonatomic, retain)NSMutableArray *name;
@end
and
//xmlToUrl.m
#import "xmlToUrl.h"
@implementation xmlToUrl
@synthesize field;
@synthesize name;
-(void)dealloc
{
[field release];
[name release];
[super dealloc];
}
@end
So this is where I am confused. I don’t know how to correctly “alloc” or “init” the mutable arrays, nor how to handle the add/remove operations from another file which inherits xmlToUrl.h.
The code (in the other file) as I have it now just prints null. Its listed below. What am I doing wrong?!?
//nodeContent is just a NSMutableString
[xmlToUrlObject.name addObject:nodeContent];
NSLog(@"xml Name = %@", xmlToUrlObject.name);
//I omitted all the operational code here but if I NSLog nodeContent it prints the correct values
[xmlToUrlObject.field addObject:nodeContent];
NSLog(@"xml Field = %@", xmlToUrlObject.field);
You need an init function in your implementation file, it would look similar to the following
Then whenever you create an instance of your xmlToUrl class via [[xmlToUrl alloc] init] you will have an instance of your class that has already initialized your two NSMutableArrays