metatext/Shared/Extensions/String+Extensions.swift
Justin Mazzocchi 167a050a89
Refactoring
2020-08-09 13:40:14 -07:00

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
}
}