Created
November 9, 2019 00:28
-
-
Save pouriaalmassi/34d74101e4f31e812988c16790449fe0 to your computer and use it in GitHub Desktop.
Random Swift image placeholder URL.
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
extension URL { | |
/// Use `let url = URL.placeholderImageUrl` | |
static var placeholderImageUrl: URL? { | |
let size = Int.random(in: 150..<800) | |
return placeholderImageUrl(with: CGSize(width: size, height: size)) | |
} | |
/// Use `let url = URL.placeholderImageUrl(with: CGSize(width: 200, height: 200))` | |
static func placeholderImageUrl(with size: CGSize) -> URL? { | |
let services = [ | |
"www.fillmurray.com", | |
"www.placecage.com", | |
"www.stevensegallery.com", | |
"placekitten.com", | |
"placebear.com", | |
] | |
return URL(string: "https://\(services[Int.random(in: 0..<services.count)])/\(Int(size.width))/\(Int(size.height))") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment