yattee/Extensions/URL+ByReplacingYatteeProtocol.swift

19 lines
551 B
Swift
Raw Normal View History

2022-12-04 12:21:50 +00:00
import Foundation
extension URL {
func byReplacingYatteeProtocol(with urlProtocol: String = "https") -> URL! {
var urlAbsoluteString = absoluteString
guard urlAbsoluteString.hasPrefix(Constants.yatteeProtocol) else {
return self
}
urlAbsoluteString = String(urlAbsoluteString.dropFirst(Constants.yatteeProtocol.count))
if absoluteString.contains("://") {
return URL(string: urlAbsoluteString)
}
return URL(string: "\(urlProtocol)://\(urlAbsoluteString)")
}
}