0

我正在使用 NSXMLParser 将 .xml 文件解析到我的项目中。到目前为止我没有问题。在我的 .xml 中是一个 ImageURL,看起来像这样:“www.fooo.com/image.jpg”来显示我需要的这个图像

urlString = [NSString stringWithFormat:@"http://%@", urlString];

这行很慢。我在循环中使用它来编辑每个值。
例如。

for (NSDictionary *locationDetails in parser.items)
{
    NSString *urlString = locationDetails[@"imageURL"];
    urlString = [NSString stringWithFormat:@"http://%@", urlString];
    NSURL *storeImageURL = [NSURL URLWithString:urlString];
    NSLog(@"img %@", urlString);
}

我的应用程序的加载时间约为 3 秒。在这条车道之后,它会增长到 20 秒!有没有办法做到同样但更快?

4

1 回答 1

1

您希望最小化发送的 obj-c 消息以及创建和销毁的临时对象的数量。为此,请尝试以下操作:

[NSURL initWitScheme:@"http" host:nil path:locationDetails[@"imageURL"]];

于 2013-04-27T06:47:35.523 回答