开发者

(iPhone) Reading from a web file - NSMutableArray

Right now I have an NSArray whose items are just written in the implementation file.

I'd like to know how to make it so I can sto开发者_运维百科re all the items on a web (text) file. Example:

http://mysite.com/files/objects.txt

On that document:

Object 0 goes here
Object 1 goes here
Object 2 goes here
Object 3 goes here

etc. All separated by a line break.

How would I be able to do this? And when I update that text file, I'd like the objects to update as well. I'd do this via an NSMutable array, correct?

Thanks in advance.


- (NSArray*)getObjectsFromWeb {
    NSURL *url = [NSURL URLWithString:@"http://mysite.com/files/objects.txt"];
    NSStringEncoding usedEncoding;
    NSError *error;
    NSString *data = [NSString stringWithContentsOfURL:url
                                          usedEncoding:&usedEncoding
                                                 error:&error];

    return [data componentsSeparatedByString:@"\n"];
}

after data is assigned here, usedEncoding (and possibly error) will have a value that you can inspect and tak action on if you like.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜