metatext/ViewModels/Sources/ViewModels/Extensions/String+Extensions.swift
2020-09-01 00:33:49 -07:00

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