What is the purpose of calling text.flatMap(URL.init) in the following:
guard let url = someUITextField.text.flatMap(URL.init) else {
return true
}
someUITextField.text is assumed to have a URL string that a user entered.
What is the purpose of calling text.flatMap(URL.init) in the following:
guard let url = someUITextField.text.flatMap(URL.init) else {
return true
}
someUITextField.text is assumed to have a URL string that a user entered.
Copyright © 2021 Jogjafile Inc.
textis an optional andURL(init)returns also an optional. The result is a double optionalURL??flatMapfirst transforms theString?toURL??then it removes one?to be able toif letthe expression.Please read What’s the difference between map(), flatMap() and compactMap()? on hackingwithswift for details.