for loop cycle showing always the last array value swift 3 after HTTP request

我的未来我决定 提交于 2019-12-02 06:40:18

You are creating the Card instance at the wrong place.

Before the inner repeat loop you are creating one instance and appending the same instance to the allCard array. If Card is a class (reference semantics) all occurrences of that instance contain the same data (the last loop item).

Put the two lines in the repeat loop.

//Write the updateJSONCards method here:
func updateJSONCards(json: JSON) {
    //create the cards
     for (set, value) in json {
         if !json[set].isEmpty {
            for i in 0..<json[set].count {
                let card = Card()
                card.cardsSet = set
                card.name = json[set][i]["name"].stringValue
                allCard.append(card)
             }
         }
         else {
             print("The set \(set) has no cards")
         }
     }
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!