Created
January 31, 2018 18:21
-
-
Save fethica/58bf46a4176e911c02fe5f09881c9f0f to your computer and use it in GitHub Desktop.
[Swift] is the URL relative or absolute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func isRelative(url: URL) -> Bool { | |
guard let regex = try? NSRegularExpression(pattern: "^(?:[a-z]+:)?//", options: .caseInsensitive) else { return false } | |
return regex.firstMatch(in: url.absoluteString, options: [], range: NSRange(location: 0, length: url.absoluteString.count)) == nil | |
} | |
let url = URL(string: "https://s3.amazonaws.com/x265.org/video/Tears_400_x265.mp4")! | |
isRelative(url: url) // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment