0

I'm using this code to assign the link of my button to the wiki page, while capturing the countryName.text in the UILabel to be a part of the URL, but Xcode gives me an error when I press it. Here's the code:

- (IBAction)openWiki:(id)sender {
NSString *sampleUrl = [[NSString alloc] initWithFormat:@"http://en.wikipedia.org/wiki/%@%@",self.countryName.text];
NSURL *wikiUrl = [[NSURL alloc] initWithString:sampleUrl];
[[UIApplication sharedApplication] openURL:wikiUrl];}

Thanks in advance.

Sergey Grischyov
  • 11,895
  • 19
  • 78
  • 118

1 Answers1

3

In your format you expect two parameters, but give only one:

@"http://en.wikipedia.org/wiki/%@%@",self.countryName.text
//                             ^^

Remove one specifier:

- (IBAction)openWiki:(id)sender {
    NSString *sampleUrl = [[NSString alloc] 
        initWithFormat:@"http://en.wikipedia.org/wiki/%@",self.countryName.text];
    //                                                ^^
    NSURL *wikiUrl = [[NSURL alloc] initWithString:sampleUrl];
    [[UIApplication sharedApplication] openURL:wikiUrl];
}
MByD
  • 133,244
  • 25
  • 260
  • 270