I am getting a strange runtime error after changing the aisShips Dictionary to the ThreadSafeDictionary:
Can't compare indices belonging to different collections
Following function is called by timer every 120 seconds. Every 20...30 minutes the app will crash with the above error. Error is caused by for (mmsi, aisShip) in aisShips
Given the time interval between crashes I suspect that the aisShips.removeValue(...) statement causes the trouble by removing a dictionary element from the dictionary. This was not an issue with the standard Dictionary.
`@objc func onAisPrune(_ timer: Timer)
{
let currentdate = Date()
for (mmsi, aisShip) in aisShips
{
if currentdate.timeIntervalSince(aisShip.aisdate) > 20 * 60
{
nmea.dbLock.wait()
aisShips.removeValue(forKey: mmsi)
aisTracks.removeValue(forKey: mmsi)
nmea.dbLock.signal()
DispatchQueue.main.async {
MapFactory.shared.removeAisTarget(mmsi: mmsi)
}
}
}
}`
I am getting a strange runtime error after changing the aisShips Dictionary to the ThreadSafeDictionary:
Can't compare indices belonging to different collections
Following function is called by timer every 120 seconds. Every 20...30 minutes the app will crash with the above error. Error is caused by
for (mmsi, aisShip) in aisShipsGiven the time interval between crashes I suspect that the
aisShips.removeValue(...)statement causes the trouble by removing a dictionary element from the dictionary. This was not an issue with the standard Dictionary.`@objc func onAisPrune(_ timer: Timer)
{
let currentdate = Date()