CutBox.app

Coverage Report

Created: 2024-03-12 03:40

.../Source/Extensions/Array+removeAtIndexes.swift
Line
Count
Source
1
//
2
//  Array+removeAtIndexes.swift
3
//  CutBox
4
//
5
//  Created by Jason Milkins on 29/4/18.
6
//  Copyright © 2018-2023 ocodo. All rights reserved.
7
//
8
9
import Foundation
10
11
extension Array {
12
3
    mutating func removeAtIndexes(indexes: IndexSet) {
13
3
        var idx: Index? = indexes.last
14
8
        while idx != nil {
15
5
            // implicit guard so we can safely force unwrap
16
5
            self.remove(at: idx!)
17
5
            idx = indexes.integerLessThan(idx!)
18
5
        }
19
3
    }
20
}
21
22
extension Array where Element == [String: String] {
23
4
    mutating func removeAll(protectFavorites: Bool) {
24
4
        if protectFavorites {
25
4
            let favorites: [[String: String]] = self.filter { $0["favorite"] == "favorite" }
26
1
            self.removeAll()
27
1
            self.append(contentsOf: favorites)
28
4
        } else {
29
3
            self.removeAll()
30
4
        }
31
4
    }
32
}