I have gone through this SO question and came to know this happens due to read and write at the same time. But in my case I am not able to figure out where I am reading and writing to my array at the same time.
What I am doing is I am removing a subrange from an array before inserting to it. e.g:
var createGameOptions = [GOCreateGameDetailsModel]()
for attribute in model.gameAttributes! {
let model = GOCreateGameDetailsModel.init(title: attribute.attribute_name!, image: nil, value: "", imageUrl: attribute.attribute_icon)
createGameOptions.append(model)
}
if (createGameModel?.createGameOptions?.count)! > 3 {
createGameModel?.createGameOptions?.removeSubrange(2...((createGameModel?.createGameOptions?.count)! - 2))
}
createGameModel?.createGameOptions?.insert(contentsOf: createGameOptions, at: 2)
Any help will be highly appreciated.