metatext/ViewModels/Sources/ViewModels/Extensions/String+Extensions.swift

22 lines
455 B
Swift
Raw Normal View History

2020-09-01 07:33:49 +00:00
// 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
}
}