Search code examples
iosswiftswift4objectmapper

How to append a array of dictionary using object mapper in swift 4?


enter image description hereenter image description hereenter image description here

After successfully logged in, I am getting this message in my console. Inside the user there is a array list named UserMedias. I want to append that UserMedias to a empty array list so that I can show the data of UserMedias in a table view. I am using just object mapper and Swift 4.

var messageList : [UserMedias] = []

Please tell me how to append the data of UserMedias into a empty array named messageList.


Solution

  • // First store the "user_medias" array in a temporary array
    
    let tempArr = resultDictionary["user_medias"] as! Array <Any>
    
    // Then run this for loop 
    
    for obj in tempArr
    {
     let tempDic = obj as! Dictionary < String,Any> 
     emptyArray.append(tempDic)  
     // here emptyArray is the array where you want to append the objects
    }