1
0
mirror of https://github.com/metabolist/metatext synced 2024-12-27 02:02:38 +01:00
metatext-app-ios-iphone-ipad/Extensions/URL+Extensions.swift
2021-02-27 13:29:30 -08:00

28 lines
727 B
Swift

// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
extension URL {
var isHTTPURL: Bool {
guard let scheme = scheme else { return false }
return scheme == "http" || scheme == "https"
}
init?(stringEscapingPath: String) {
guard let pathEscaped = stringEscapingPath.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)
else { return nil }
let httpsColonUnescaped = pathEscaped.replacingOccurrences(
of: "https%3A",
with: "https:",
range: pathEscaped.range(of: "https%3A"))
self.init(string: httpsColonUnescaped)
}
}
extension URL: Identifiable {
public var id: String { absoluteString }
}