I have a URL string (NSString
) with spaces and &
characters. How do I url encode the entire string (including the &
ampersand character and spaces)?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
In my case where the last component was Arabic letters I did the following in
Swift 2.2
:usage:
Use NSURLComponents to encode HTTP GET parameters:
http://www.ralfebert.de/snippets/ios/encoding-nsurl-get-parameters/
Here's a production-ready flexible approach in Swift 4:
Example usage:
Output:
//This is without test
This code helped me for encoding special characters
Apple's advice, in the 10.11 release notes, is:
If you need to percent-encode an entire URL string, you can use this code to encode a NSString intended to be a URL (in urlStringToEncode):