1
0
mirror of https://github.com/metabolist/metatext synced 2024-12-26 17:52:26 +01:00
metatext-app-ios-iphone-ipad/Shared/Extensions/String+Extensions.swift

22 lines
507 B
Swift
Raw Normal View History

// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
extension String {
private static let colonDoubleSlash = "://"
func url(scheme: String = "https") throws -> URL {
let url: URL?
if hasPrefix(scheme + Self.colonDoubleSlash) {
url = URL(string: self)
} else {
url = URL(string: scheme + Self.colonDoubleSlash + self)
}
guard let validURL = url else { throw URLError(.badURL) }
return validURL
}
}