Skip to content

Instantly share code, notes, and snippets.

@ratulSharker
Created April 17, 2018 06:21
Show Gist options
  • Save ratulSharker/e3ad4bc7d9f5a81b939d753edc017c96 to your computer and use it in GitHub Desktop.
Save ratulSharker/e3ad4bc7d9f5a81b939d753edc017c96 to your computer and use it in GitHub Desktop.
Extension for creating URL using non-supporting character like (whitespaces / unicode) etc.
//
// URL+PercentEncoding.swift
//
// Created by ratul sharker on 4/4/18.
//
import Foundation
extension URL {
static func initWithPercentEncoding(string : String) -> URL? {
let encodedString = string.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)
if let encodedString = encodedString {
return URL.init(string: encodedString)
} else {
return nil
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment