Skip to content

Commit b9d0efd

Browse files
committed
Merge pull request #111 from ParsePlatform/nlutsenko.operationSet
Add ability to remove all field operations from PFOperationSet.
2 parents 3cfc1bb + 058a1a1 commit b9d0efd

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

Parse/Internal/Object/OperationSet/PFOperationSet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@
6565
- (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey;
6666
- (void)setObject:(id)anObject forKeyedSubscript:(id<NSCopying>)aKey;
6767
- (void)removeObjectForKey:(id)aKey;
68+
- (void)removeAllObjects;
6869

6970
@end

Parse/Internal/Object/OperationSet/PFOperationSet.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ - (void)removeObjectForKey:(id)key {
166166
self.updatedAt = [NSDate date];
167167
}
168168

169+
- (void)removeAllObjects {
170+
[self.dictionary removeAllObjects];
171+
self.updatedAt = [NSDate date];
172+
}
173+
169174
///--------------------------------------
170175
#pragma mark - NSFastEnumeration
171176
///--------------------------------------

Tests/Unit/OperationSetUnitTests.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,24 @@ - (void)testRemoveObjectForKey {
103103
XCTAssertNotEqualObjects(date, operationSet.updatedAt);
104104
}
105105

106+
- (void)testRemoveAllObjects {
107+
PFOperationSet *operationSet = [[PFOperationSet alloc] init];
108+
109+
operationSet[@"yarr"] = [PFSetOperation setWithValue:@"a"];
110+
operationSet[@"yolo"] = [PFAddOperation addWithObjects:@[ @"b" ]];
111+
112+
XCTAssertNotNil(operationSet[@"yarr"]);
113+
XCTAssertNotNil(operationSet[@"yolo"]);
114+
XCTAssertEqual(operationSet.count, 2);
115+
116+
NSDate *date = operationSet.updatedAt;
117+
[operationSet removeAllObjects];
118+
XCTAssertNil(operationSet[@"yarr"]);
119+
XCTAssertNil(operationSet[@"yolo"]);
120+
XCTAssertEqual(operationSet.count, 0);
121+
XCTAssertNotEqualObjects(date, operationSet.updatedAt);
122+
}
123+
106124
- (void)testCopying {
107125
PFOperationSet *operationSet = [[PFOperationSet alloc] init];
108126
operationSet[@"yarr"] = [PFSetOperation setWithValue:@"yolo"];

0 commit comments

Comments
 (0)