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

前端 未结 1 753
天命终不由人
天命终不由人 2021-01-24 08:37

I already used another post to solver part of the problem,so now I am able to wait the end of the request. I made a http request with Almofire and parse the resulting JSON file.

1条回答
  •  故里飘歌
    2021-01-24 09:26

    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..

    0 讨论(0)
提交回复
热议问题