mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-26 02:01:00 +00:00
21 lines
455 B
Swift
21 lines
455 B
Swift
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
import Foundation
|
|
|
|
extension String {
|
|
private static let HTTPSPrefix = "https://"
|
|
|
|
func url() throws -> URL {
|
|
let url: URL?
|
|
|
|
if hasPrefix(Self.HTTPSPrefix) {
|
|
url = URL(string: self)
|
|
} else {
|
|
url = URL(string: Self.HTTPSPrefix + self)
|
|
}
|
|
|
|
guard let validURL = url else { throw URLError(.badURL) }
|
|
|
|
return validURL
|
|
}
|
|
}
|