gpt4 book ai didi

swift - 网址错误 : Unexpectedly found nil while unwrapping an Optional value: file

转载 作者:行者123 更新时间:2023-11-30 10:31:21 27 4
gpt4 key购买 nike

我正在使用 WinguGallery pod。我想查看我从 MSSQL 与 wingugallerry 拍摄的链接中的照片。我可以成功提取数据。但是“让 asset = ImageAsset (url: url!)我在“我成功从数据库中检索数据。但可能在 url 部分定义变量时。我获取的数据是字符串变量。

import UIKit
import WinguGallery

class GelisimController: UIViewController {
func fillWithGifs() {

let client = SQLClient.sharedInstance()!
client.connect("ddd", username: "ddd", password: "ddd", database: "ddd") { success in
client.execute("SELECT ddd FROM ddd", completion: { (_ results: ([Any]?)) in
var gifsa: [String] = []
for table in results as! [[[String:AnyObject]]] {

for row in table {

for (_, value) in row {

if let intVal = value as? String {
gifsa.append(String(intVal))
var returnArray: [ImageAsset?] = [ImageAsset]()
for item in gifsa {
let url = URL(string: item)
let asset = ImageAsset(url: url!) //error line
returnArray.append(asset)
}
self.winguGalleryView.assets = returnArray
print("returnArray", gifsa)
}} }}
client.disconnect()
})}
}

最佳答案

像这样修改你的 for 循环

for item in gifsa {
guard let url = URL(string : item) else {continue}
//Rest of the code here
}

如果您不确定这些值,请不要强行打开包装。 :)

关于swift - 网址错误 : Unexpectedly found nil while unwrapping an Optional value: file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59152549/

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