LoginSignup
1
3

More than 5 years have passed since last update.

SwiftでRFC3986に準拠したパーセントエンコードをするやつのSwift 3版です。

Last updated at Posted at 2017-03-08

アンパサンド(&)も対象に含めたPercent EncodingをするStringのExtensionが欲しく。

なかなか3以前のものしか見つからず・・・

手元で Swift 3にしたスニペットをメモ。 :bow: ツカッテクダサイ。

extension String {
    func stringByAddingPercentEncodingForRFC3986() -> String? {
        let unreserved = "-._~/?"
        var allowed = CharacterSet.alphanumerics
        allowed.insert(charactersIn: unreserved)
        return addingPercentEncoding(withAllowedCharacters: allowed)
    }
}

出典

UTF8 Encoding in iOS / swift for email containing +
http://stackoverflow.com/questions/39093990/utf8-encoding-in-ios-swift-for-email-containing

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3