[英]How do I check in Swift if a variable with a datatype of URL is empty?
I'm trying to check if my url is nil or not since I have a background thread that is getting the url from my database. 我正在尝试检查我的网址是否为零,因为我有一个后台线程从我的数据库获取网址。
I tried doing this travelURL.absoluteString == ""
and travelURL != nil
but the problem still persists. 我试过这个
travelURL.absoluteString == ""
和travelURL != nil
但问题仍然存在。
I declared my variable as var travelURL: URL!
我将我的变量声明为
var travelURL: URL!
You can use if let
syntax: 您可以使用
if let
语法:
if let url = travelURL {
// Here you can use url, it is not nil
} else {
// Here url is nil
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.