如何解决如何设置新值以更改我的Story应用程序的问题
我想根据用户选择更改故事。但是,每次我运行该应用程序时,它总是显示相同的问题。具体来说,是第30行和第41行。我不想在那儿写0,但IDK怎么办。我确实拥有不混淆的“结构”。
var hikayeler = [
Story(
title: "Your car has blown a tire on a winding road in the middle of nowhere with no cell phone reception. You decide to hitchhike. A rusty pickup truck rumbles to a stop next to you. A man with a wide brimmed hat with soulless eyes opens the passenger door for you and asks: 'Need a ride,boy?'.",choice1: "I'll hop in. Thanks for the help!",choice1Destination: 2,choice2: "Better ask him if he's a murderer first.",choice2Destination: 1
),Story(
title: "He nods slowly,unfazed by the question.",choice1: "At least he's honest. I'll climb in.",choice2: "Wait,I know how to change a tire.",choice2Destination: 3
),
解决方法
一种选择是在决定选择哪个故事时使用随机数:
let index = Int.random(0..<hikayeler.count)
另一种选择是记录用户看到过哪些故事,以确保他们在启动时总是得到不同的故事。
由您决定要如何运行您的应用。
编辑-为了使故事继续进行,您需要一个存储当前索引的变量。
class ViewController: UIViewController {
var index = 0
@IBAction func button1(_ sender: UIButton) {
let variable1 = hikayeler[index]
...
index = variable1
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。