ios – SwiftUI, Picture View not matching with chosen enum case particulars

0
2
ios – SwiftUI, Picture View not matching with chosen enum case particulars


On this cellular Rock, Paper, Scissors sport I am creating, I count on to have particular Picture and Textual content Views populate to symbolize the consumer’s and laptop’s transfer. To this point, the right Picture and Textual content View seems for the consumer however not for the pc. The logic is sound, as I’ve used a number of print statements to verify to see if the small print for a randomly chosen enum case are all the identical however for some cause, the Picture and Textual content View differ from the pc’s transfer. I am too new to essentially perceive what’s going on, can anybody supply an evidence in order that I can give you an answer? Please let me know if extra info 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), Pc 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 {
        swap self {
        case .rock:
                .rock
        case .paper:
                .paper
        case .scissors:
                .scissors
        }
    }

    var iconTitle: String {
        swap 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(top: 100)
        
            Textual content(moveTitle)
                .font(.title)
                .italic()
                .foregroundStyle(.black)
            
        }
        .padding(10)
    }
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here