On this cell Rock, Paper, Scissors sport I am creating, I anticipate to have particular Picture and Textual content Views populate to characterize the person’s and laptop’s transfer. To date, the right Picture and Textual content View seems for the person however not for the pc. The logic is sound, as I’ve used a number of print statements to test to see if the main points for a randomly chosen enum case are all the identical however for some motive, the Picture and Textual content View differ from the pc’s transfer. I am too new to actually perceive what’s going on, can anybody provide an evidence in order that I can give you an answer? Please let me know if extra data is required.
struct PlayerVSComputerView: View {
var randomRawValue = Int.random(in: 0...2)
var physique: some View {
NavigationView{
ZStack{
VStack{
let computerChoice = MoveOptionModel(rawValue: randomRawValue)!
MoveOptionIcon(moveImage: computerChoice.id.iconImage, moveTitle: computerChoice.id.iconTitle)
HStack{
// different Views
}// HStack Finish
.onAppear {
print("Uncooked Worth: (randomRawValue), Laptop Selection: (computerChoice), Icon Title: (computerChoice.id.iconTitle), ID: (computerChoice.id)")
}
}// VStack Finish
}// ZStack Finish
}// NavigationView Finish
}// physique Finish
}
enum MoveOptionModel: Int, CaseIterable, Identifiable {
case rock = 0
case paper = 1
case scissors = 2
var id: MoveOptionModel { self }
var iconImage: ImageResource {
change self {
case .rock:
.rock
case .paper:
.paper
case .scissors:
.scissors
}
}
var iconTitle: String {
change self {
case .rock:
"Rock"
case .paper:
"Paper"
case .scissors:
"Scissors"
}
}
}
struct MoveOptionIcon: View {
let moveImage: ImageResource
let moveTitle: String
var physique: some View {
VStack{
Picture(moveImage)
.resizable()
.scaledToFit()
.body(peak: 100)
Textual content(moveTitle)
.font(.title)
.italic()
.foregroundStyle(.black)
}
.padding(10)
}
}