检查var是否是swift中的URL

时间:2018-02-22 14:15:00

标签: swift url

如何测试变量是否为url? 成为网址的条件是什么?

1 个答案:

答案 0 :(得分:1)

你可以用以下方法测试它:

var maybeUrl = "http://is.this.an.url"

if let url = URL(string:maybeUrl) {
    // work with the url
}