Skip to content

Instantly share code, notes, and snippets.

@fethica
Created January 31, 2018 18:21
Show Gist options
  • Save fethica/58bf46a4176e911c02fe5f09881c9f0f to your computer and use it in GitHub Desktop.
Save fethica/58bf46a4176e911c02fe5f09881c9f0f to your computer and use it in GitHub Desktop.
[Swift] is the URL relative or absolute
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