URL - 在展开可选值时发现 nil
URL - Found nil while unwrapping an Optional value
我对这个 post 有点惭愧,因为我一直都在使用 URL,但是这个让我很困惑!
我不断收到 'Unexpectedly found nil while unwrapping an Optional value'
只是为了添加一些上下文,我对 20 多个 URL 使用相同的格式,它们正在向 API 发出请求。唯一的区别是URL.
末尾的ID
忽略不安全的 URL,因为这只是一个调试端点,与问题无关,因为我在其他调用中使用相同的 URL。另外,请忽略 URL 的第一部分,为了安全起见,我特意更改了它。
我使用的代码如下:
func returnEventParticipantsEndPoint(eventID: String) -> URLRequest {
print("URL: \(debugEndPointURL)/api/friendgroups/\(eventID)")
var url: URL!
url = URL(string: "\(debugEndPointURL)/api/friendgroups/\(eventID)")!
let requestURL = URLRequest(url: url)
return requestURL
}
在我尝试 return URL 请求之前打印在控制台(顶行)中的 URL 打印如下:
http://blahblahblah.blah.net/api/friendgroups/1c8264b95884409f90b4fd8ba9d830e1
然而,它保持 returning 为零,我真的很感谢对此的一些帮助...谢谢。
你复制并粘贴了这个格式吗?检查字符串,您在 api
和 friendgroups
之后有一些不可打印的 Unicode 字符。重新输入 url 路径并再次尝试对我有效
失败的原因是您的字符串中存在隐藏的 Unicode 字符。将您提供的 url 字符串复制并粘贴到隐藏的 Unicode 字符检查器中,可以为您的 url
提供以下内容
http://blahblahblah.blah.net/apiU+200B/friendgroupsU+200B/1c8264b95884409f90b4fd8ba9d830e1
注意单词 api
和 friendgroups
末尾的附加隐藏字符
我对这个 post 有点惭愧,因为我一直都在使用 URL,但是这个让我很困惑! 我不断收到 'Unexpectedly found nil while unwrapping an Optional value'
只是为了添加一些上下文,我对 20 多个 URL 使用相同的格式,它们正在向 API 发出请求。唯一的区别是URL.
末尾的ID忽略不安全的 URL,因为这只是一个调试端点,与问题无关,因为我在其他调用中使用相同的 URL。另外,请忽略 URL 的第一部分,为了安全起见,我特意更改了它。
我使用的代码如下:
func returnEventParticipantsEndPoint(eventID: String) -> URLRequest {
print("URL: \(debugEndPointURL)/api/friendgroups/\(eventID)")
var url: URL!
url = URL(string: "\(debugEndPointURL)/api/friendgroups/\(eventID)")!
let requestURL = URLRequest(url: url)
return requestURL
}
在我尝试 return URL 请求之前打印在控制台(顶行)中的 URL 打印如下: http://blahblahblah.blah.net/api/friendgroups/1c8264b95884409f90b4fd8ba9d830e1
然而,它保持 returning 为零,我真的很感谢对此的一些帮助...谢谢。
你复制并粘贴了这个格式吗?检查字符串,您在 api
和 friendgroups
之后有一些不可打印的 Unicode 字符。重新输入 url 路径并再次尝试对我有效
失败的原因是您的字符串中存在隐藏的 Unicode 字符。将您提供的 url 字符串复制并粘贴到隐藏的 Unicode 字符检查器中,可以为您的 url
提供以下内容http://blahblahblah.blah.net/apiU+200B/friendgroupsU+200B/1c8264b95884409f90b4fd8ba9d830e1
注意单词 api
和 friendgroups