Fixed: Previoulsly, clearsFilterPredicateOnInsertion was applied (removes filter predicate) when setting content or on content binding. (#2860)

With Tests: Foundation unit test.
Solves #2791
This commit is contained in:
cacaodev authored and Martin Carlberg committed 2019-11-12 14:02:35 +01:00
1 parent ac68fec6b1
commit 623ad2b1dc
2 files changed
+21 -10

No files matched your search

+1 -10
View File
@@ -297,27 +297,18 @@
class.
*/
if (_clearsFilterPredicateOnInsertion)
[self willChangeValueForKey:@"filterPredicate"];
// Don't use [super setContent:] as that would fire the contentObject change.
// We need to be in control of when notifications fire.
// Note that if we have a contentArray binding, setting the content does /not/
// cause a reverse binding set.
_contentObject = value;
if (_clearsFilterPredicateOnInsertion && _filterPredicate != nil)
[self __setFilterPredicate:nil]; // Causes a _rearrangeObjects.
else
[self _rearrangeObjects];
[self _rearrangeObjects];
if ([self preservesSelection])
[self __setSelectedObjects:oldSelectedObjects];
else
[self __setSelectionIndexes:oldSelectionIndexes];
if (_clearsFilterPredicateOnInsertion)
[self didChangeValueForKey:@"filterPredicate"];
}
/*!
+20
View File
@@ -1020,6 +1020,26 @@
[self assertTrue:[[arrayController arrangedObjects] count] > 0];
}
- (void)testArrangedObjectsWhenSetContentAndClearsFilterOnInsertionIsTrue
{
var arrayController = [[CPArrayController alloc] init];
[arrayController setClearsFilterPredicateOnInsertion:YES];
[arrayController setFilterPredicate:[CPPredicate predicateWithValue:NO]];
[arrayController setContent:[CPArray arrayWithObject:@"a"]];
[self assertTrue:[[arrayController arrangedObjects] count] == 0];
}
- (void)testArrangedObjectsWhenBindingAndClearsFilterOnInsertionIsTrue
{
var arrayController = [[CPArrayController alloc] init];
[arrayController setClearsFilterPredicateOnInsertion:YES];
[arrayController setFilterPredicate:[CPPredicate predicateWithValue:NO]];
[arrayController bind:@"contentArray" toObject:self withKeyPath:@"_contentArray" options:nil];
[self assertTrue:[[arrayController arrangedObjects] count] == 0];
}
- (void)testArrangedObjectsWithPredicateFilteringAfterContentArrayBinding
{
_contentArray = [self makeTestArray];