I have an array of custom class and I want to make a change to one of the items in it. 

```
var mainArray = [MainOrder]()

//Now imagine that mainArray has a bunch of different items in it.  

struct MainOrder:Codable {
    var time:Date?
    var order_id:String?
    var side:String?
}

```

What is the best way to do that? Right now I find the index then I move it into a new variable then I delete the item from the array and then add it back again like you see below. But I am sure this is better way to do this. 

```
if let tempIndex = self.mainArray.index(where: {$0.side == "left"}) {
    var tempVar = self.mainArray[tempIndex]
    tempVar.time = Date()
    self.mainArray.remove(at: tempIndex)
    self.mainArray.insert(tempVar, at: tempIndex)
}

```