【发布时间】:2010-04-11 14:31:53
【问题描述】:
首先,我对 Objective C 和 iPhone 编程非常陌生。现在这已经不成问题了。我已经阅读了大部分 Apple 文档以及一些第三方手册。
我想我只是想知道我是否以正确的方式处理这件事......
- (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;
}
结果的输出是...
(
{
HASSTORIES = NO;
NAME = News;
URL = "http://www.mycoolnewssite.com/api/v1/news/news/25/stories.json";
},
{
HASSTORIES = NO;
NAME = Sports;
URL = "http://www.mycoolnewssite.com/api/v1/news/sports/25/stories.json";
},
{
HASSTORIES = NO;
NAME = Entertainment;
URL = "http://www.mycoolnewssite.com/api/v1/news/entertainment/25/stories.json";
},
{
HASSTORIES = NO;
NAME = Business;
URL = "http://www.mycoolnewssite.com/api/v1/news/business/25/stories.json";
},
{
HASSTORIES = NO;
NAME = Features;
URL = "http://www.mycoolnewssite.com/api/v1/news/features/25/stories.json";
}
)
任何见解将不胜感激;-)
【问题讨论】:
-
也许......你想要完成什么? (例如,您要检查哪一部分的正确性?)
标签: iphone objective-c ipad nsmutablearray