调用text.flatmap(url.init)的目的是什么?
在以下内容中调用text.flatmap(url.init)的目的是什么:
guard let url = someUITextField.text.flatMap(URL.init) else {
return true
}
假定someuitextfield.text具有用户输入的URL字符串。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文本
是可选的,url(init)
也返回也是可选的。结果是双重可选url ??
flatmap
首先将String?
转换为url ??
然后它删除一个?
能够如果让
表达式。请阅读 ),flatmap()和compactmap()?在hackingwithwithswift上以获取详细信息。
text
is an optional andURL(init)
returns also an optional. The result is a double optionalURL??
flatMap
first transforms theString?
toURL??
then it removes one?
to be able toif let
the expression.Please read What’s the difference between map(), flatMap() and compactMap()? on hackingwithswift for details.