1
votes

I'm having an NSObject class where i have an init method defined something like below,

- (id)initWithPlistName:(NSString *)plistFileName{
    if (self = [super init]) {
        plistName = plistFileName;
        plistContent = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] 
                                                                pathForResource:plistName ofType:@"plist"]]; // this plistContent array is not allocating in memory
    }
    return self;
}

I'm calling this method in my applications AppDelegate Class didFinishLaunchingWithOptions method, plistContent is my iVar of type NSArray but whenever control comes to plistContent alloc init line and while returning self, there is no memory allocated for my array. What may be the problem happening here, Any help is appreciated in advance.

3
How have u allocated the initializing of object in appDelegate - AppleDelegate
show d code of ur didFinish in appDelegate.. - vishy
i have edited my answer, please look .. - Shamsudheen TK

3 Answers

1
votes

I suppose you have not changed the Datatype of your plist root key in your plist flie from dictionary to array

1
votes

Check file exists:

NSString *path = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"];
if(path)
{
   plistContent = [[NSArray alloc] initWithContentsOfFile:path]; 
}
else
{
  NSLog(@"File Not exists");
}
0
votes

Try this

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"plistName" ofType:@"plist"];
NSDictionary *myDict = [[NSDictionary alloc] initWithContentsOfFile:filePath];
NSArray *array = [NSArray arrayWithArray:[myDict objectForKey:@"Root"]];