Created
October 23, 2019 16:02
Revisions
-
hishma created this gist
Oct 23, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ import Foundation extension String { public func addingPercentEncodingForRFC3986() -> String? { let unreserved = "-._~/?" let allowed = NSMutableCharacterSet.alphanumeric() allowed.addCharacters(in: unreserved) return self.addingPercentEncoding(withAllowedCharacters: allowed as CharacterSet) } public func addingPercentEncodingForFormData(plusForSpace: Bool=false) -> String? { let unreserved = "*-._" let allowed = NSMutableCharacterSet.alphanumeric() allowed.addCharacters(in: unreserved) if plusForSpace { allowed.addCharacters(in: " ") } var encoded = self.addingPercentEncoding(withAllowedCharacters: allowed as CharacterSet) if plusForSpace { encoded = encoded?.replacingOccurrences(of: " ", with: "+") } return encoded } }