title: Swift dictionary silently doesn't store new items
body: <p>I need some advice. Here is the code. I'm trying to add items to the Dictionary after deleting some of them. But nothing changes. Why? Where am I wrong?</p>
  
  <p>This struct just as demo with <code>Equatable</code> protocol implemented.</p>
  
  <pre><code>struct Card: Equatable {
      static func == (lhs: Card, rhs: Card) -&gt; Bool {
          return
              (lhs.color == rhs.color ||
                  lhs.number == rhs.number ||
                  lhs.shading == rhs.shading ||
                  lhs.symbol == rhs.symbol)
      }
      var number = 0
      var symbol = 0
      var shading = 0
      var color = 0
  
      var isSelected = false
      var isSet = false
  }
  </code></pre>
  
  <p>This is a card-game model, in this example just as demo to show </p>
  
  <pre><code>struct gameSet {
      var cards = [Card]()
      var cardField = [Int:Card]()
  
      init () {
          for num in 1...3 {
              for sym in 1...3 {
                  for sha in 1...3 {
                      for col in 1...3 {
                          cards += [Card(number: num, symbol: sym, shading: sha, color: col, isSelected: false, isSet: false)]
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Int's extension to get random numbers</p>
  
  <pre><code>extension Int {
      var random: Int {
          return Int(arc4random_uniform(UInt32(self)))
      }
  }
  var game = gameSet()
  
  // cardField gets 24 random items from game.cards
  
  var cardCount = 24
  
  repeat {
      let randomCard = game.cards[(game.cards.count-1).random]
      game.cardField[game.cardField.count] = randomCard
      game.cards.remove(at: game.cards.index(of: randomCard)!)
      cardCount -= 1
  } while cardCount != 0
  
  // we got 24 items in cardField dictionary
  print(game.cardField.count)
  
  // delete 3 random items from cardField
  
  for _ in 1...3 {
      let randomKey = game.cardField.count.random
      game.cardField.removeValue(forKey: randomKey)
  }
  
  // we got 21 items in cardField dictionary, ok
  print(game.cardField.count)
  
  // let's add 3 another items to cardField dictionary same way
  var cardCount2 = 3
  
  repeat {
      let randomCard = game.cards[(game.cards.count-1).random]
      game.cardField[game.cardField.count] = randomCard
      game.cards.remove(at: game.cards.index(of: randomCard)!)
      cardCount2 -= 1
  } while cardCount2 != 0
  
  // nothing changed! cardFiled still have 21 items as after deletion WHY???
  print(game.cardField.count)
  </code></pre>
  
  <p>Is there any value - reference nuances, that I don't know about?</p>