title: Swift Firebase doesn't store Bool
body: <p>I am having two ViewControllers, one called <code>ComposingOverviewViewController</code> and another one called <code>CheapestViewController</code>.
  If the User presses a Button, he/ she ;) will be shown the <code>CheapestViewController</code>. If the user presses &quot;Choose&quot;, <code>cheapestBool</code>becomes <code>true</code>. The selection made should be stored in Firebase, with the bool set as &quot;true&quot;, so it can be checked afterwards, if the selection should be shown or not. Even when I check it while saving the data to firebase, Xcode tells me that the value is actually &quot;true&quot;. But in Firebase it gets stored as &quot;false&quot;.</p>
  <p>I have to say, that to actually show something in <code>CheapestViewController</code>, the User has first to press the Button <code>check Values</code>. Since I am aware, that as soon as the View switches back again from <code>CheapestViewController</code>to <code>ComposingOverviewViewController</code>the generated Selection gets lost. So as soon as the User presses &quot;Save&quot; in the <code>ComposingOverviewController</code> the selection gets generated again.</p>
  <p>Maybe it has to do something with this.
  I deleted as much unnecessary code as possible.
  Hope that's okay for everyone!</p>
  <p>But I actually don't have any clue.
  Maybe someone can help. :)</p>
  <pre><code>class ComposingOVerviewViewController: UIViewController {
  
   
      @IBOutlet weak var cheapestImageView: UIImageView!
      
      var individualimageViewBool = false
      var cheapestimageviewBool = false
      var efficientImageViewBool = false
      var bestImageViewBool = false
      var overAllBestImageViewBool = false
      var DollarJPerfor:Double?
      var projectCreated:String?
      let uid = User.current.uid
      
      var indivCompValue = [WeighScore]()
      var projCompValue = [ProjCompValue]()
      
      var projectBudget:Int = 0
      var projectDifficulty:Double = 0
      var projectCreativity:Double = 0
  
      var finalCheapest: [WeighScore] = []
      
      var cheapestBool:Bool?
      
      var freelancerArray = [WeighScore]()
      
      var jobAmountNeeded = [JobNeeded]()
  
      
      override func viewDidLoad() {
          super.viewDidLoad()
  
          UserService.projectjobamount(for: User.current, projectCreated: projectCreated ?? &quot;no Value&quot;) { (jobNeeded) in
              self.jobAmountNeeded = jobNeeded
          }
              
          UserService.individualComposingValues(for: User.current) { (indivCompValue) in
              self.freelancerArray = indivCompValue
          }
          projectSpecification(for: User.current, projectCreated: projectCreated ?? &quot;no Value&quot;)
          
          imageHighlights()
                  
  
         
      }
      
     
  
  // MARK: - Highlighten the Images when Team selected
      
      func imageHighlights() {
          
          if individualimageViewBool == true {
          individualImageView.image = UIImage(named: &quot;Individual-1&quot;)
          } else {
          individualImageView.image = UIImage(named: &quot;Individual&quot;) }
          
          if cheapestimageviewBool == true {
              cheapestImageView.image = UIImage(named: &quot;cheapesthigh&quot;)
              cheapestBool = true
              
          }
          else { cheapestImageView.image = UIImage(named: &quot;Cheapest&quot;) }
          
          if efficientImageViewBool == true {
              efficientImageView.image = UIImage(named: &quot;Efficient-1&quot;)
          }
              
          else {  efficientImageView.image = UIImage(named: &quot;Efficient&quot;) }
          
          if bestImageViewBool == true {
              bestImageView.image = UIImage(named: &quot;Besthighlight&quot;) }
          else {bestImageView.image = UIImage(named: &quot;Best&quot;) }
          
          if overAllBestImageViewBool == true {
              overAllBestImageView.image = UIImage(named: &quot;absolutbesthigh&quot;) }
          else {overAllBestImageView.image = UIImage(named: &quot;absolutbest&quot;) }
  }
  
      
  func getCheapest(member: [WeighScore], neededValue: [JobNeeded]) {
      var tempArray1: [WeighScore] = []
  
             for jobAmount in jobAmountNeeded {
                 
             let neededValue = jobAmount.jobAmount
             tempArray1 = freelancerArray.filter { $0.memberJob == jobAmount.jobName}
              let amountInArray = tempArray1.count
  
              if neededValue == 0 { return
                     } else if neededValue == amountInArray{
                      tempArray1.sort(by: {$0.normalPrice! &lt; $1.normalPrice!})
                      for value in tempArray1 {
                          print(value.memberName as Any)
                             print(tempArray1.count)
                             finalBest.append(value) }
                
              } else {
              tempArray1.sort(by: {$0.normalPrice! &lt; $1.normalPrice!})
              let deletedValue = tempArray1.count - neededValue
              print(&quot;deleted Value: &quot;, deletedValue)
                  tempArray1.remove(0..&lt;deletedValue)
                  for value in tempArray1 {
                      print(value.memberName as Any)
                  print(tempArray1.count)
                  finalCheapest.append(value)
              }
          }
      }
  }
  
      
      
  // MARK: - Button Function to check Values only
      @IBAction func checkValues(_ sender: Any) {
          
      getBest(member: freelancerArray, neededValue: jobAmountNeeded, budgetLevel: projectBudget)
      getAbsolutBest(member: freelancerArray, neededValue: jobAmountNeeded)
      getMostEfficient(member: freelancerArray, neededValue: jobAmountNeeded)
      getCheapest(member: freelancerArray, neededValue: jobAmountNeeded)
      
  }
          
  // MARK: - Save the Team/ Teams
      
      @IBAction func saveAction(_ sender: Any) {
          print(cheapestBool)
          
          getCheapest(member: freelancerArray, neededValue: jobAmountNeeded)
          
         
          for value in finalCheapest {
              let finalCheapest = &quot;finalCheapest&quot;
              PostService.proposedTeams(projectCreated: projectCreated ?? &quot;No Value&quot;, teamType: finalCheapest, memberJob: value.memberJob ?? &quot;no value&quot;, memberName: value.memberName ?? &quot;no Value&quot;, memberID: value.memberID ?? &quot;no Value&quot;, ajp: value.ajp ?? 999, crea: value.crea ?? 999, ijr: value.ijr ?? 999, qpa: value.qpa ?? 999, coj: value.coj ?? 999, los: value.los ?? 999, iracc: value.iracc ?? 999, dph: value.dph ?? 999, normalPrice: value.normalPrice ?? 999, sumFreelanceRating: value.sumFreelanceRating ?? 999, priceJPerfScore: value.priceJPerfScore ?? 999, teamSelected: cheapestBool ?? false)
          }
      }
      
  
  // MARK: - Pass data to specific ViewController of Team Alternatives
      
      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
           if segue.identifier == &quot;teamToCheapest&quot; {
              let destVC = segue.destination as! CheapestViewController
              print(sentcheapestTeam.count)
              destVC.finalCheapest = finalCheapest
          }
      
      }
      
  
      
  //    MARK: - Go to specific Teams
      
      
     
      @IBAction func cheapest(_ sender: Any) {
          
         
          
          performSegue(withIdentifier: &quot;teamToCheapest&quot;, sender: self)
  
      }
      
     
  }
  
  
  // MARK: - Extensions
  
  extension Array {
   
     mutating func remove(_ range: Range&lt;Int&gt;) -&gt; Array {
        let values = Array(self[range])
        self.removeSubrange(range)
        return values
     }
  }
  </code></pre>
  <pre><code>class CheapestViewController: UIViewController {
  
      
  // MARK: - Properties
      
     @IBOutlet weak var tableView: UITableView!
      
      
  //    var VC = ComposingOVerviewViewController()
      var finalCheapest = [WeighScore]()
  
          
          
          override func viewDidLoad() {
              super.viewDidLoad()
  
              // Do any additional setup after loading the view.
          }
      
      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
          if segue.identifier == &quot;cheapestToOverview&quot; {
              let destVC = segue.destination as! ComposingOVerviewViewController
              
              destVC.cheapestBool = true
          }
      }
          
  
      @IBAction func chooseCheapest(_ sender: Any) {
          
          print(finalCheapest.count)
          for value in finalCheapest {
              print(value.memberJob)
          
          }
          performSegue(withIdentifier: &quot;cheapestToOverview&quot;, sender: self)
  
  
      }
      
  
      }
  </code></pre>
  <pre><code>class WeighScore {
      
      var key: String?
      let memberJob: String?
      let memberName: String?
      let memberID:String?
      let ajp: Double?
      let crea:Double?
      let ijr:Double?
      let qpa:Double?
      let coj:Double?
      let los:Double?
      let iracc:Double?
      let dph:Double?
      let normalPrice:Double?
      var sumFreelanceRating:Double?
      let priceJPerfScore:Double?
      
          
      
      init(ajp: Double, crea:Double, ijr:Double, qpa:Double, coj:Double, los:Double, iracc:Double, dph:Double, sumFreelanceRating:Double, normalPrice:Double, memberJob: String, memberName: String, priceJPerfScore:Double, memberID:String) {
              
          self.ajp = ajp
          self.crea = crea
          self.ijr = ijr
          self.qpa = qpa
          self.coj = coj
          self.los = los
          self.iracc = iracc
          self.dph = dph
          self.sumFreelanceRating = sumFreelanceRating
          self.normalPrice = normalPrice
          self.memberName = memberName
          self.memberJob = memberJob
          self.priceJPerfScore = priceJPerfScore
          self.memberID = memberID
    
          }
      
      
      var dictValue: [String: Any] {
          
          return [&quot;memberName&quot; : memberName,
                  &quot;memberJob&quot; : memberJob,
                  &quot;ajp&quot; : ajp,
                  &quot;crea&quot; : crea,
                  &quot;ijr&quot; : ijr,
                  &quot;qpa&quot; : qpa,
                  &quot;coj&quot; : coj,
                  &quot;los&quot; : los,
                  &quot;iracc&quot; : iracc,
                  &quot;dph&quot; : dph,
                  &quot;normalPrice&quot;: normalPrice,
                  &quot;sumFreelanceRating&quot; : sumFreelanceRating,
                  &quot;priceJPerfScore&quot;: priceJPerfScore,
                  &quot;memberID&quot;: memberID,
                  ]
          
  
      }
      init?(snapshot: DataSnapshot) {
          guard let dict = snapshot.value as? [String: Any],
              
              let memberJob = dict[&quot;memberJob&quot;] as? String,
              let memberName = dict[&quot;memberName&quot;] as? String,
              let ajp = dict[&quot;ajp&quot;] as? Double,
              let crea = dict[&quot;crea&quot;] as? Double,
              let ijr = dict[&quot;ijr&quot;] as? Double,
              let qpa = dict[&quot;qpa&quot;] as? Double,
              let coj = dict[&quot;coj&quot;] as? Double,
              let los = dict[&quot;los&quot;] as? Double,
              let iracc = dict[&quot;iracc&quot;] as? Double,
              let dph = dict[&quot;dph&quot;] as? Double,
              let normalPrice = dict[&quot;normalPrice&quot;] as? Double,
              let sumFreelanceRating = dict[&quot;sumFreelanceRating&quot;] as? Double,
              let priceJPerfScore = dict[&quot;priceJPerfScore&quot;] as? Double,
              let memberID = dict[&quot;memberID&quot;] as? String
            
          
              else {return nil}
                           self.memberJob = memberJob
                           self.memberName = memberName
                           self.ajp = ajp
                           self.crea = crea
                           self.ijr = ijr
                           self.qpa = qpa
                           self.coj = coj
                           self.los = los
                           self.iracc = iracc
                           self.dph = dph
                           self.normalPrice = normalPrice
                           self.sumFreelanceRating = sumFreelanceRating
                           self.priceJPerfScore = priceJPerfScore
                           self.memberID = memberID
      }
      
  }
  
  class TeamSetting {
      
      var key: String?
      let memberJob: String?
      let memberName: String?
      let memberID:String?
      let ajp: Double?
      let crea:Double?
      let ijr:Double?
      let qpa:Double?
      let coj:Double?
      let los:Double?
      let iracc:Double?
      let dph:Double?
      let normalPrice:Double?
      var sumFreelanceRating:Double?
      let priceJPerfScore:Double?
      var teamSelected: Bool?
      
          
      
      init(ajp: Double, crea:Double, ijr:Double, qpa:Double, coj:Double, los:Double, iracc:Double, dph:Double, sumFreelanceRating:Double, normalPrice:Double, memberJob: String, memberName: String, priceJPerfScore:Double, memberID:String, teamSelected: Bool) {
              
          self.ajp = ajp
          self.crea = crea
          self.ijr = ijr
          self.qpa = qpa
          self.coj = coj
          self.los = los
          self.iracc = iracc
          self.dph = dph
          self.sumFreelanceRating = sumFreelanceRating
          self.normalPrice = normalPrice
          self.memberName = memberName
          self.memberJob = memberJob
          self.priceJPerfScore = priceJPerfScore
          self.memberID = memberID
          self.teamSelected = teamSelected
    
          }
      
      
      var dictValue: [String: Any] {
          
          return [&quot;memberName&quot; : memberName,
                  &quot;memberJob&quot; : memberJob,
                  &quot;ajp&quot; : ajp,
                  &quot;crea&quot; : crea,
                  &quot;ijr&quot; : ijr,
                  &quot;qpa&quot; : qpa,
                  &quot;coj&quot; : coj,
                  &quot;los&quot; : los,
                  &quot;iracc&quot; : iracc,
                  &quot;dph&quot; : dph,
                  &quot;normalPrice&quot;: normalPrice,
                  &quot;sumFreelanceRating&quot; : sumFreelanceRating,
                  &quot;priceJPerfScore&quot;: priceJPerfScore,
                  &quot;memberID&quot;: memberID,
                  &quot;teamSelected&quot;: teamSelected]
          
  
      }
      init?(snapshot: DataSnapshot) {
          guard let dict = snapshot.value as? [String: Any],
              
              let memberJob = dict[&quot;memberJob&quot;] as? String,
              let memberName = dict[&quot;memberName&quot;] as? String,
              let ajp = dict[&quot;ajp&quot;] as? Double,
              let crea = dict[&quot;crea&quot;] as? Double,
              let ijr = dict[&quot;ijr&quot;] as? Double,
              let qpa = dict[&quot;qpa&quot;] as? Double,
              let coj = dict[&quot;coj&quot;] as? Double,
              let los = dict[&quot;los&quot;] as? Double,
              let iracc = dict[&quot;iracc&quot;] as? Double,
              let dph = dict[&quot;dph&quot;] as? Double,
              let normalPrice = dict[&quot;normalPrice&quot;] as? Double,
              let sumFreelanceRating = dict[&quot;sumFreelanceRating&quot;] as? Double,
              let priceJPerfScore = dict[&quot;priceJPerfScore&quot;] as? Double,
              let memberID = dict[&quot;memberID&quot;] as? String,
              let teamSelected = dict[&quot;teamSelected&quot;] as? Bool
            
          
              else {return nil}
                           self.memberJob = memberJob
                           self.memberName = memberName
                           self.ajp = ajp
                           self.crea = crea
                           self.ijr = ijr
                           self.qpa = qpa
                           self.coj = coj
                           self.los = los
                           self.iracc = iracc
                           self.dph = dph
                           self.normalPrice = normalPrice
                           self.sumFreelanceRating = sumFreelanceRating
                           self.priceJPerfScore = priceJPerfScore
                           self.memberID = memberID
                           self.teamSelected = teamSelected
      }
      
  }
  
  </code></pre>