Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simultaneous accesses to 0x6040000155d8, but modification requires exclusive access

Tags:

arrays

ios

swift

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.

like image 509
iPeter Avatar asked Dec 17 '25 11:12

iPeter


1 Answers

You should try updating this line

createGameModel?.createGameOptions?.removeSubrange(2...((createGameModel?.createGameOptions?.count)! - 2))

To

let count = (createGameModel?.createGameOptions?.count)!
createGameModel?.createGameOptions?.removeSubrange(2...(count - 2))

Try and share the results

like image 94
Bhavin Kansagara Avatar answered Dec 19 '25 04:12

Bhavin Kansagara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!