0

Here is my code.

NSString *target = @"http://www.google.com/";
NSString *html = [NSString stringWithContentsOfURL: [NSURL URLWithString:@"%@", target] encoding: -2147481280 error: nil];

My code gives me the error above

Too many arguments to method call expected 1 have 2

Somebody help me..

Screenshot for error

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
SaeHyun Kim
  • 475
  • 2
  • 8
  • 26
  • check this http://stackoverflow.com/questions/3995519/how-to-use-stringwithcontentsofurlencodingerror – Huy Nghia Jul 11 '14 at 08:45
  • [NSURL URLWithString:@"%@", target] -> URLWithString take a NSString as parameter, not a formatedString. The solution is replace by [NSURL URLWithString:target]. – Duyen-Hoa Jul 11 '14 at 08:48

3 Answers3

1

Issue is with the following code snippet:

[NSURL URLWithString:@"%@", target]

You don't need to specify the type specifier there.

You need to change your code like:

NSString *target = @"http://www.google.com/";
NSString *html = [NSString stringWithContentsOfURL: [NSURL URLWithString:target] encoding:NSUTF8StringEncoding error: nil];
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • @trojanfoe: I Just fixed that, I just copied the code from question and only changed the issue causing part :) – Midhun MP Jul 11 '14 at 08:49
0

Choose one of these.

NSString *html = [NSString stringWithContentsOfURL: [NSURL URLWithString:[NSString stringWithFormat:@"%@", target]] encoding: -2147481280 error: nil];

or

NSString *html = [NSString stringWithContentsOfURL: [NSURL URLWithString:target] encoding: -2147481280 error: nil];
Ryan
  • 4,799
  • 1
  • 29
  • 56
0

You can use like that as well just one line of code:-

NSString *html = [NSString stringWithContentsOfURL:[[NSURL alloc] initWithString:@"http://www.google.com/"] encoding:NSUTF8StringEncoding error: nil];
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56