/
FilterType.swift
54 lines (41 loc) · 1.36 KB
/
FilterType.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// FilterType.swift
// WWDC
//
// Created by Guilherme Rambo on 25/05/17.
// Copyright © 2017 Guilherme Rambo. All rights reserved.
//
import Foundation
protocol FilterType {
var identifier: FilterIdentifier { get set }
var isEmpty: Bool { get }
var predicate: NSPredicate? { get }
mutating func reset()
}
extension Array where Element == FilterType {
/// This performs a comparison to ensure the two arrays
/// have the same elements by comparing their identifiers
///
/// It is very slow. If the size of the arrays or frequency
/// of use becomes greater in the future, a new approach
/// may be required
func isIdentical(to otherArray: [Element]) -> Bool {
var isIdentical = false
if self.count == otherArray.count {
isIdentical = true
for filter in self {
if !otherArray.contains(where: {
if let mc0 = $0 as? MultipleChoiceFilter, let mc1 = filter as? MultipleChoiceFilter {
return mc0.identifier == mc1.identifier && mc0.options == mc1.options
} else {
return $0.identifier == filter.identifier
}
}) {
isIdentical = false
break
}
}
}
return isIdentical
}
}