2020-07-29 23:50:30 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
extension String {
|
2020-08-09 20:40:14 +00:00
|
|
|
private static let HTTPSPrefix = "https://"
|
2020-07-29 23:50:30 +00:00
|
|
|
|
2020-08-09 20:40:14 +00:00
|
|
|
func url() throws -> URL {
|
2020-07-29 23:50:30 +00:00
|
|
|
let url: URL?
|
|
|
|
|
2020-08-09 20:40:14 +00:00
|
|
|
if hasPrefix(Self.HTTPSPrefix) {
|
2020-07-29 23:50:30 +00:00
|
|
|
url = URL(string: self)
|
|
|
|
} else {
|
2020-08-09 20:40:14 +00:00
|
|
|
url = URL(string: Self.HTTPSPrefix + self)
|
2020-07-29 23:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
guard let validURL = url else { throw URLError(.badURL) }
|
|
|
|
|
|
|
|
return validURL
|
|
|
|
}
|
|
|
|
}
|