gpt4 book ai didi

ios - 转换[字节]?到[字节]

转载 作者:搜寻专家 更新时间:2023-10-31 22:53:42 28 4
gpt4 key购买 nike

嗨,我是 swift 的新手,我正在尝试解码以 [Byte] 形式发回给我的字节数组?当我尝试使用

if let string = String(bytes: d, encoding: .utf8) {
print(string)
} else {
print("not a valid UTF-8 sequence")
}

它说需要解包。我无法更改返回可选数组的基本代码,因为它是从框架返回的。

最佳答案

使用guard let

guard let unwrappedBytes = d else { return }

有了这个,您将获得与以前完全相同的数据,但没有问号。

我知道很难理解 Swift 中的可选内容。我建议查看 Apple Docs,它非常好: https://developer.apple.com/documentation/swift/optional

关于ios - 转换[字节]?到[字节],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53555369/

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