I am creating an app where I need to modify specific bytes in a Data object, but it crashes when I modify too many bytes at one time.
I thought the problem might be because my app was hanging for too long, but I put my code in a DispatchGroup and it didn’t help.
//amount and interval are Ints
var pos: Int = 1
let count = data.count
var tempData: Data = data
while (pos < count) {
tempData[pos - 1] = tempData[pos - 1] + UInt8(amount)
pos += interval
}
This code crashes my app when I provide it with a large Data object, but works fine with small ones.