Created
August 23, 2016 13:34
-
-
Save FranDepascuali/3b8b3152b06ba8562e83b84b45f4682c to your computer and use it in GitHub Desktop.
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
protocol Downloader { | |
func fetch(from url: SecureURLType) | |
} | |
protocol SecureURLType { | |
init?(from url: URL, validator: URL -> Bool) | |
} | |
private let DefaultValidator: URL -> Bool = { _ in true } | |
struct SecureURL: SecureURLType { | |
private let _url: URL | |
init?(from url: URL, validator: URL -> Bool = DefaultValidator) { | |
guard validator(url) else { | |
return nil | |
} | |
_url = url | |
} | |
} | |
let url = NSURL(string: "https://www.google.com.ar/")! | |
guard let secureURL = SecureURL(from: url) else { | |
print("Cannot make a request to an internal ip!") | |
} |
print("Cannot make a request to an internal ip!")
Hardcoded string
let DefaultValidator: URL -> Bool = { _ in true }
Posta, te parece que _ in true
es claro? Vos que tanto queres que todo sea claro. Y este encima es un caso tonto. No es intuitivo, simplemente es una 'convencion' de funcional.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Che que es NSURL? No es un nombre claro