dimanche 11 août 2019

Used SwiftUI picker and my MacBook heats up to 50 degrees

As soon as I use a code, my MacBook heats up to 50 degrees. I have 4 Enums that each have a picker, as soon as I put 3 pickers into an if-else statement and then debug, my MacBook heats up so much that I almost do it can not touch anymore.

i use the enums with the protocols Int16, Hashable, CaseIterable. i want Int16 for my CoreData Attribut. If i change Int16 to Int then the Code Works..

Import SwiftUI
struct EnumsInEnums: View {
          @State  var pickMain = 0
          @State  var pickA = 0
          @State  var pickB = 0
          @State  var pickC = 0

enum MainEnum :  Int16, Hashable, CaseIterable
        {
        case AEnum
        case BEnum
        case CEnum
        var name: String { return "\(self)" }
        }
enum AEnum :  Int16, Hashable, CaseIterable
        {
        case Aa
        case Ba
        case Ca
        var name: String { return "\(self)" }
        }
enum BEnum :  Int16, Hashable, CaseIterable
        {
        case Ab
        case Bb
        case Cb
        var name: String { return "\(self)" }
        }
enum CEnum :  Int16, Hashable, CaseIterable
        {
        case Ac
        case Bc
        case Cc
        var name: String { return "\(self)" }
}
var body: some View {
 NavigationView {
  Form {
   Section {

   Picker(selection: $pickMain, label: Text("Pick \(pickMain)")) {
                 ForEach(MainEnum.allCases, id: \.self){ x in
                 Text("\(x.name)").tag(Int(x.rawValue))
                 }
                    }
    if pickMain == 0 {
       Picker(selection: $pickA, label: Text("Pick \(pickA)")) {
                  ForEach(AEnum.allCases, id: \.self){ x in
                  Text("\(x.name)").tag(Int(x.rawValue))
                  }
             }
       } else if pickMain == 1 {
       Picker(selection: $pickB, label: Text("Pick \(pickB)")) {
                  ForEach(BEnum.allCases, id: \.self){ x in
                  Text("\(x.name)").tag(Int(x.rawValue))
                  }
             }
       } else if pickMain == 2 {
       Picker(selection: $pickC, label: Text("Pick \(pickC)")) {
                  ForEach(CEnum.allCases, id: \.self){ x in
                  Text("\(x.name)").tag(Int(x.rawValue))
                  }
            }
      }
     }
    }
   }
  }
 }

I expect to select the Main and then the second picker will show me the selected, as if I would select an automaker and in the second picker come the respective car model.

Aucun commentaire:

Enregistrer un commentaire