gpt4 book ai didi

ios - 在元组中追加值

转载 作者:行者123 更新时间:2023-11-30 13:26:24 25 4
gpt4 key购买 nike

任何人都可以告诉我如何从我的 favBt 函数在 tuple 中附加值。我尝试了两种不同的方法但出现同样的错误?

fatal error: unexpectedly found nil while unwrapping an Optional value

1. appendData.tupple.append(values)
2. appendData.tupple.append(url,image)

enter image description here

var objects : [(String, String)] = [
("https://www.youtube.com/watch?v=9h30Bx4Klxg","1.jpg"),
("https://www.youtube.com/watch?v=ij_0p_6qTss","2.jpg"),
("https://www.youtube.com/watch?v=AJtDXIazrMo","3.jpg"),
("https://www.youtube.com/watch?v=H202k7KfZL0","4.jpg"),
("https://www.youtube.com/watch?v=CGyEd0aKWZE","5.jpg"),
("https://www.youtube.com/watch?v=AtKZKl7Bgu0","6.jpg"),
("https://www.youtube.com/watch?v=4SYlLi5djz0","7.jpg")]

func favBt(sender: UIButton){

var btn : NSInteger
btn = sender.tag as NSInteger

let (url,image) = objects[btn]

let values = (url, image)
print(values)

let appendData = ViewController()

appendData.tupple.append(values)

print(appendData.tupple[btn])

}

In my ViewController Class

class ViewController: UIViewController{
var tuple : [(String, String)]?
}

最佳答案

letappendData = ViewController() 我从函数外部创建它。

替换它var tuple : [(String, String)]?

var 元组:[(String, String)] = []

关于ios - 在元组中追加值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37134396/

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