Reputation: 2007
I'm building an iOS app that displays ranged iBeacons in a TableViewController.
To improve performances and test the new Swift 5.1 diffing feature I wrote the following code:
private func updateBeacons(_ rangedBeacons: [CLBeacon]) {
guard beacons != rangedBeacons else { return }
let difference = rangedBeacons.difference(from: beacons)
// Also tried:
// let difference = rangedBeacons.difference(from: beacons, by: { $0.uuid == $1.uuid })
// ...
}
When this code is reached a fatalError
is thrown:
Fatal error: unsupported: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1100.2.259.70/swift/stdlib/public/core/ArrayBuffer.swift, line 231
How can I perform collection diffing on CLBeacon
s?
The referenced code can be found here: https://github.com/apple/swift/blob/master/stdlib/public/core/ArrayBuffer.swift#L226-L232
Upvotes: 8
Views: 427
Reputation: 697
I was hitting this issue as well, but in my case I was getting one of the arrays from a Core Data NSFetchedResultsController. I suspect it's related to the fact that the original array comes from Objective-C.
I was able to fix this by wrapping the arrays in a new Array:
private func updateBeacons(_ rangedBeacons: [CLBeacon]) {
guard beacons != rangedBeacons else { return }
let difference = Array(rangedBeacons).difference(from: Array(beacons))
// ...
}
Upvotes: 8