hanumanDev
hanumanDev

Reputation: 6614

How to output plist items into an array

I'm trying to output the results from the following plist where checked is 1 (checked is a BOOL from the plist). The issue I'm having is that when I try to output the text into a providersArray it outputs them one after another and not in one array like "text1,text2,text3," etc...

My syntax is causing me the problem. any help would be great.

NSString *path = [[NSBundle mainBundle] pathForResource:@"Providers" ofType:@"plist"];
dataArray = [NSMutableArray arrayWithContentsOfFile:path];
for (NSDictionary *dictionary in dataArray)
{
    text = [dictionary valueForKey:@"text"];
    checked = [dictionary valueForKey:@"checked"];
    NSLog(@"%@ checked value is: %@", text, checked);


    if ([checked boolValue]) {
        NSString *providers = [NSString stringWithFormat:@"%@",text ];
        NSLog(@"providers are %@", providers);

       NSArray *providersArray = [text componentsSeparatedByString:@","];

      NSLog(@"providersArray are %@", providersArray);


    }

}

Upvotes: 1

Views: 72

Answers (1)

Anoop Vaidya
Anoop Vaidya

Reputation: 46543

Place NSArray *providersArray out of loop.

To prevent it from getting initialized again and again and lose its previous value, use addObject: on it.

Upvotes: 2

Related Questions