Skip to content

Commit 6f51b94

Browse files
committed
Improve the Filter+predicate documentation
1 parent eded9cf commit 6f51b94

File tree

1 file changed

+24
-34
lines changed

1 file changed

+24
-34
lines changed

Sources/StreamChat/Query/Filter+predicate.swift

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,11 @@
55
import Foundation
66

77
extension Filter {
8-
/// If a valueMapper was provided, then here we will try to transform the value
9-
/// using the mapper.
10-
///
11-
/// If the mapper returns nil, the original value will be returned
12-
var mappedValue: FilterValue {
13-
valueMapper?(value) ?? value
14-
}
15-
16-
/// If the mappedValues is an array of FilterValues, we will try to transform them using the valueMapper
17-
/// to ensure that both parts of the comparison are of the same type.
18-
///
19-
/// If the value is not an array, this value will return nil.
20-
/// If the valueMapper isn't provided or the value mapper returns nil, the original value will be included
21-
/// in the array.
22-
var mappedArrayValue: [FilterValue]? {
23-
guard let filterArray = mappedValue as? [FilterValue] else {
24-
return nil
25-
}
26-
return filterArray.map { valueMapper?($0) ?? $0 }
27-
}
28-
29-
/// If it can be translated, this will return
30-
/// an NSPredicate instance that is equivalent
31-
/// to the current filter.
32-
///
33-
/// For now it's limited to ChannelList as it's not
34-
/// needed anywhere else
8+
/// Converts the current filter into an NSPredicate if it can be translated.
359
///
36-
/// The predicate will be automatically be used
37-
/// by the ChannelDTO to create the
38-
/// fetchRequest.
10+
/// This is useful to make sure the backend filters can be used to filter data in CoreData.
3911
///
40-
/// - Important:
41-
/// The behaviour of the ChannelDTO, to include or not
42-
/// the predicate in the fetchRequest, it's controlled by
43-
/// `ChatClientConfig.isChannelAutomaticFilteringEnabled`
12+
/// **Note:** Extra data properties will be ignored since they are stored in binary format.
4413
var predicate: NSPredicate? {
4514
guard let op = FilterOperator(rawValue: `operator`) else {
4615
return nil
@@ -234,6 +203,27 @@ extension Filter {
234203
return nil
235204
}
236205
}
206+
207+
/// If a valueMapper was provided, then here we will try to transform the value
208+
/// using the mapper.
209+
///
210+
/// If the mapper returns nil, the original value will be returned
211+
var mappedValue: FilterValue {
212+
valueMapper?(value) ?? value
213+
}
214+
215+
/// If the mappedValues is an array of FilterValues, we will try to transform them using the valueMapper
216+
/// to ensure that both parts of the comparison are of the same type.
217+
///
218+
/// If the value is not an array, this value will return nil.
219+
/// If the valueMapper isn't provided or the value mapper returns nil, the original value will be included
220+
/// in the array.
221+
var mappedArrayValue: [FilterValue]? {
222+
guard let filterArray = mappedValue as? [FilterValue] else {
223+
return nil
224+
}
225+
return filterArray.map { valueMapper?($0) ?? $0 }
226+
}
237227
}
238228

239229
extension String {

0 commit comments

Comments
 (0)