Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stringByAddingPercentEscapesUsingEncoding was deprecated in 9.0 .How to do this?

Tags:

objective-c

I'm a junior developer, and I got a code for this:

(NSString *)encodedStringFromObject:(id)object {     return [[object description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];     } 

But in 9.0 have to use stringByAddingPercentEncodingWithAllowedCharacters.

How Could I transfer this code ? I need help, Thanks!

like image 530
Just Lai Avatar asked Dec 01 '15 08:12

Just Lai


2 Answers

If you want just fast example look at this code:

NSString * encodedString = [@"string to encode" stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]; 

Also check List of predefined characters sets

If you want explanation read the documents or at least this topic: How to encode a URL in Swift

like image 84
sage444 Avatar answered Sep 21 '22 02:09

sage444


URL = [[NSString stringWithFormat:@"%@XYZ",API_PATH]stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; 
like image 23
Ishwar Hingu Avatar answered Sep 17 '22 02:09

Ishwar Hingu