I currently have a struct in which my ViewController references to return a random value from a group of arrays (aList, bList, cList, & dList). I ideally would like to be have aList always enabled while being able to toggle bList, cList, & dList on/off.
I have all this in a struct (shown below) but I'm very new to Swift and am learning that structs are "value types" while the ViewController is a "reference type" and apparently UI objects can only be referenced from reference types?
import GameKit
import Foundation
struct PromptProvider {
var aListIndex = 0
var bListIndex = 0
var cListIndex = 0
var dListIndex = 0
var includeB = false
var includeC = false
var includeD = false
var aList = [
“A1”,
“A2”,
“A3”,
“A4”]
var bList = [
“B1”,
“B2”,
“B3”,
“B4”]
var cList = [
“C1”,
“C2”,
“C3”,
“C4”]
var dList = [
“D1”,
“D2”,
“D3”,
“D4”]
init() {
self.restart()
}
mutating func restart() {
if includeB == true {self.aList.append(contentsOf: bList)}
if includeC == true {self.aList.append(contentsOf: cList)}
if includeD == true {self.aList.append(contentsOf: dList)}
self.aList.shuffle()
self.aListIndex = 0
}
mutating func randomPrompt() -> String {
if aListIndex == aList.count {
return "Out of String Values"
}
else {
defer {aListIndex += 1}
return aList[aListIndex]
}
}
}
I think I'm treating the struct as a reference type here but am unable to connect a UI object to the structs code.
Any help/guidance on how to pivot my strategy with this would be greatly appreciated. Thank you