PercentEncoder 1.2.1

PercentEncoder 1.2.1

LangLanguage SwiftSwift
License MIT
ReleasedLast Release Nov 2017
SwiftSwift Version 4.0
SPMSupports SPM

Maintained by Kazunobu Tasaka, kitoko552.


PercentEncoder is a lightweight library to escape string using so called URL encoding in Swift.


PercentEncoder uses JavaScriptCore framework for URL-encoding although URL-encoding is executed with CFURLCreateStringByAddingPercentEscapes() or NSString.stringByAddingPercentEncodingWithAllowedCharacters() in most cases.
The followings is the reason and has motivated me to make this library.

  • CFURLCreateStringByAddingPercentEscapes() deprecated in iOS9
  • NSString.stringByAddingPercentEncodingWithAllowedCharacters() is introduced from iOS 7. However it won’t work in multi-byte languages like Japanes, Chinese, etc and an app crashes as shown at the issue in Alamorefire.


PercentEncoder offers PercentEncoding enum and String extension methos for URL-encoding.


PercentEncoding has four values which are equivalent to Javscript functions(encodeURI, encodeURIComponent, decodeURI, decodeURIComponent).

let url = "東京&year='20"

/// EncodeURI
let escaped = PercentEncoding.EncodeURI.evaluate(string: url)
// encoded to "'20"

/// DecodeURI
PercentEncoding.DecodeURIComponent.evaluate(string: escaped)
// decoded back to "東京&year='20"

let value = "東京" // 東京 means Tokyo which is the capital of Japan.

/// EncodeURI
let encoded = PercentEncoding.EncodeURIComponent.evaluate(string: value)
// encoded to "%E6%9D%B1%E4%BA%AC"

/// DecodeURI
PercentEncoding.DecodeURIComponent.evaluate(string: encoded)
// decoded back to "東京"

String extension

PercentEncoding offers String extension methods which are equivalent to Javscript functions(encodeURI, encodeURIComponent, decodeURI, decodeURIComponent).

/// encodeURI

/// decodeURI

/// encodeURIComponent
let encoded = "東京".ped_encodeURIComponent()
// encoded to "%E6%9D%B1%E4%BA%AC"

/// decodeURIComponent
// decoded back to "東京"


  • Swift 3.0
  • Xcode 8.0
  • iOS 8.0+


  • Install with Cocoapods

    platform :ios, '8.0'
    pod 'PercentEncoder'
  • Git submodule

Release Notes



PercentEncoder is released under the MIT license. See LICENSE for details.