0

on following code i'm get the error message: Implicit conversion of 'NSStringEncoding' (aka 'unsigned long') to 'NSCharacterSet * _Nonnull' is disallowed with ARC

Where i'm making wrong?

NSURL *candidatesURL = [NSURL URLWithString:[str_url
                                             stringByAddingPercentEncodingWithAllowedCharacters:NSUTF8StringEncoding]];

1 Answers1

0

You are using the wrong method. Instead of using stringByAddingPercentEncodingWithAllowedCharacters use this stringByAddingPercentEscapesUsingEncoding

If you wan't to use this method stringByAddingPercentEncodingWithAllowedCharacters you have to pass a set of allowed characters.

Try this.

NSURL *candidatesURL = [NSURL URLWithString:[str_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

Or if you app development target is IOS 9.0 and above.

stringByAddingPercentEscapesUsingEncoding is deprecated so you can use stringByAddingPercentEncodingWithAllowedCharacters and use URLHostAllowedCharacterSet.

NSURL *candidatesURL = [NSURL URLWithString:[str_url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
Bilal
  • 18,478
  • 8
  • 57
  • 72
  • but when i use that method give the warning that this is deprecated method – Bhumi Nandola Nov 03 '17 at 04:46
  • This is deprecated. Check out this link : https://stackoverflow.com/questions/32242712/replacement-for-stringbyaddingpercentescapesusingencoding-in-ios9 – Sunny Shah Nov 03 '17 at 04:48
  • @BhumiNandola Yes it's deprecated but the `stringByAddingPercentEncodingWithAllowedCharacters` is available for IOS9 and above. See updated answer. – Bilal Nov 03 '17 at 04:54