2 import CloudKitCodeProtobuf
7 import SecurityFoundation
10 internal static func removingDuplicates(vouchers: Set<VoucherMO>) -> Set<VoucherMO> {
11 var unique: Set<VoucherMO> = Set()
13 for voucher in vouchers {
14 if !unique.contains(voucher) {
15 unique.insert(voucher)
21 internal static func onqueueRemoveDuplicateVouchersPerPeer(container: ContainerMO, moc: NSManagedObjectContext) {
22 var peersWithUniqueSetOfVouchers: Set<PeerMO> = Set()
23 let peers = container.peers as? Set<PeerMO> ?? Set()
25 let vouchers = peer.vouchers as? Set<VoucherMO> ?? Set()
26 let uniqueSet = Container.removingDuplicates(vouchers: vouchers)
27 for voucher in vouchers {
28 peer.removeFromVouchers(voucher)
30 for voucher in uniqueSet {
31 peer.addToVouchers(voucher)
33 peersWithUniqueSetOfVouchers.insert(peer)
36 container.removeFromPeers(peer)
38 for peer in peersWithUniqueSetOfVouchers {
39 container.addToPeers(peer)