NSMutableArray of Objects

Posted by Terry Owen on Stack Overflow See other posts from Stack Overflow or by Terry Owen
Published on 2010-04-11T14:31:53Z Indexed on 2010/04/11 14:33 UTC
Read the original article Hit count: 403

First off I am very new to Objective C and iPhone programming. Now that that is out of the way. I have read through most of the Apple documentation on this and some third party manuals.

I guess I just want to know if I'm going about this the correct way ...

- (NSMutableArray *)makeModel {

    NSString *api = @"http://www.mycoolnewssite.com/api/v1";

    NSArray *namesArray = [NSArray arrayWithObjects:@"News", @"Sports", @"Entertainment", @"Business", @"Features", nil];

    NSArray *urlsArray = [NSArray arrayWithObjects:
                      [NSString stringWithFormat:@"%@/news/news/25/stories.json", api],
                      [NSString stringWithFormat:@"%@/news/sports/25/stories.json", api],
                      [NSString stringWithFormat:@"%@/news/entertainment/25/stories.json", api],
                      [NSString stringWithFormat:@"%@/news/business/25/stories.json", api],
                      [NSString stringWithFormat:@"%@/news/features/25/stories.json", api], nil];

    NSMutableArray *result = [NSMutableArray array];

    for (int i = 0; i < [namesArray count]; i++) {
        NSMutableDictionary *objectDict = [NSMutableDictionary dictionary];
        NSString *name = (NSString *)[namesArray objectAtIndex:i];
        NSString *url = (NSString *)[urlsArray objectAtIndex:i];
        [objectDict setObject:name forKey:@"NAME"];
        [objectDict setObject:url forKey:@"URL"];
        [objectDict setObject:@"NO" forKey:@"HASSTORIES"];
        [result addObject:objectDict];
    }

    return result;
}

Any insight would be appreciated ;-)

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone