mirror of
https://github.com/metabolist/metatext.git
synced 2024-12-02 04:50:59 +00:00
21 lines
507 B
Swift
21 lines
507 B
Swift
// 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
|
|
}
|
|
}
|