views:

19

answers:

1

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 store 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.

+1  A: 
- (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.

Squeegy
Thanks, I'll try it.
Alex