NSString to NSURL objects

Posted by user337844 on Stack Overflow See other posts from Stack Overflow or by user337844
Published on 2010-05-11T02:29:59Z Indexed on 2010/05/11 2:34 UTC
Read the original article Hit count: 374

Filed under:
|
|
|
|

Hello, I have an array that I populated with my plist file, which looks something like this:

<array>
   <string>http://www.apple.com</string>
   <string>http://www.google.com</string>
   <string>http://www.amazon.com</string>
</array>

So, I'm looking to convert these NSString objects to NSURL objects when I call them in my didSelectRowAtIndexPath method. Any ideas?

This is what I have right now:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


     NSInteger row = [indexPath row];

     if (self.viewController == nil) {
          TemplateViewController *details = [[TemplateViewController alloc] initWithNibName:@"TemplateViewController" bundle:nil];
          self.viewController = details;
          [details release];
     }


     NSString *tempURLString = [tieroneurlArray objectAtIndex:row];
     NSURL *loadingUrl = [NSURL URLWithString:tempURLString];
     [tieroneurlArray addObject:loadingUrl];

     viewController.title = [NSString stringWithFormat:@"%@", [tieroneArray objectAtIndex:row]];

     [self.viewController setTableURL:[tieroneurlArray objectAtIndex:row]];     

     TemplateAppAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
     [delegate.templateNavController pushViewController:viewController animated:YES];
}

And this is how I load the array with the plist:

- (void)viewDidLoad {
    [super viewDidLoad];

     NSString *path = [[NSBundle mainBundle] pathForResource:@"tier1Names" ofType:@"plist"];
     tieroneArray = [[NSMutableArray alloc] initWithContentsOfFile:path];

     NSString *tableURL = [[NSBundle mainBundle] pathForResource:@"tier1URL" ofType:@"plist"];     
     tieroneurlArray = [[NSMutableArray alloc] initWithContentsOfFile:tableURL];
}

© Stack Overflow or respective owner

Related posts about nsstring

Related posts about nsurl