gpt4 book ai didi

swift - NSURL 失败初始化器 initWithString : does not return nil on empty String in Swift

转载 作者:搜寻专家 更新时间:2023-11-01 06:43:44 25 4
gpt4 key购买 nike

很容易在 Playground 中重现

import Foundation

let urlString = ""

let url = NSURL(string: urlString)

print(url)

url 的结果不知何故是 (no URL) 而不是预期的 nil并且打印输出是 Optional(),既没有 .Some 也没有 .None

我真的很想对这个有一些了解,因为它让我感到惊讶并导致生产代码崩溃。

最佳答案

在我为此填充雷达后,我得到了以下答案:

Apple Developer Relations

An empty string is a valid URL string. It has no scheme, no authority (user/password/host/port), an empty path, no query and no fragment.

所以它似乎按预期工作。

关于swift - NSURL 失败初始化器 initWithString : does not return nil on empty String in Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32784552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com