Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift URL对象在使用let常量字符串URL创建后为零_Swift - Fatal编程技术网

Swift URL对象在使用let常量字符串URL创建后为零

Swift URL对象在使用let常量字符串URL创建后为零,swift,Swift,为什么第一个例子给了我一个nil,第二个例子给了我一个有效的URL对象。我试图使用这个jsonUrlString常量,但它不起作用 一, 二, 第一个例子在URL中有很多额外的空格,因此它是无效的 这与: let temp = URL(string: " https://myURI.domain.com/") 如果您有: let jsonUrlString = """ https://myURI.domain.com/ """ 这定义了不带额外空

为什么第一个例子给了我一个nil,第二个例子给了我一个有效的URL对象。我试图使用这个jsonUrlString常量,但它不起作用

一,

二,


第一个例子在URL中有很多额外的空格,因此它是无效的

这与:

let temp = URL(string: "                        https://myURI.domain.com/")
如果您有:

let jsonUrlString = """
https://myURI.domain.com/
"""
这定义了不带额外空格的字符串

let temp = URL(string: "                        https://myURI.domain.com/")
let jsonUrlString = """
https://myURI.domain.com/
"""