我正在下载一个文本文件并使用其中的信息来创建多个对象。如何处理文本文件中的不同类型的信息
我用下面的代码来实现这一目标:
NSString *fileContents = [NSString stringWithContentsOfURL: readerView.url
encoding: NSUTF8StringEncoding
error: NULL];
NSArray *lines = [fileContents componentsSeparatedByString:@"\n"];
for(NSString *line in lines)
{
NSArray *params = [line componentsSeparatedByString:@","];
NSString *label1 = [params objectAtIndex:0];
NSString *label2 = [params objectAtIndex:1];
float weight = [[params objectAtIndex:2] floatValue];
int x1 = [[params objectAtIndex:3] intValue];
int y1 = [[params objectAtIndex:4] intValue];
int x2 = [[params objectAtIndex:5] intValue];
int y2 = [[params objectAtIndex:6] intValue];
int type = [[params objectAtIndex:7] intValue];
[graph addComponents:label1:label2 :weight :x1 :y1 :x2 :y2 :type];
}
在文本文件中的行的一个例子是,像这样:
A,B,6.0,270,190,150,190,1
所以这是非常基本的。我想要做的是为文本文件的第一行或最后一行添加一个可触发另一个图像下载的URL。我想不出什么是实现这一目标的最佳方式。在我的脑海里,我想在伪代码是这样的:
如果(行=第一行)
触发下载
其他
经过PARAMS。
我刚试过这个,它似乎没有检查它是否是一个URL。我在'if(url)'之后放了一个NSLog,并且它看起来不管它是否是url都被打印出来。 – 2010-11-10 09:51:51