1
votes

I'm grabbing data from an external file using NSURL with the code below. If i wanted to grab this data from an internal file in my resources folder how would the code be different.

here's the NSURL code:

NSURL *dataUrl = [NSURL URLWithString:@"https://sites.google.com/site/*****/***/file.asc"]; NSString *fileString = [NSString stringWithContentsOfURL:dataUrl encoding:NSUTF8StringEncoding error:nil];

this was my attempt:

NSString *path = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"asc"]; NSString *fileString = [NSString initWithContentsOfFile:path];

thanks in advance

1
And... what's wrong with your attempt?jtbandes

1 Answers

2
votes

Maybe try stringByExpandingTildeInPath
something like

    NSString *path = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"asc"];
    path = [path stringByExpandingTildeInPath];
    NSString *fileString = [NSString initWithContentsOfFile:path];