Skip to content

Add ability to remove all field operations from PFOperationSet. #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Parse/Internal/Object/OperationSet/PFOperationSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@
- (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey;
- (void)setObject:(id)anObject forKeyedSubscript:(id<NSCopying>)aKey;
- (void)removeObjectForKey:(id)aKey;
- (void)removeAllObjects;

@end
5 changes: 5 additions & 0 deletions Parse/Internal/Object/OperationSet/PFOperationSet.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ - (void)removeObjectForKey:(id)key {
self.updatedAt = [NSDate date];
}

- (void)removeAllObjects {
[self.dictionary removeAllObjects];
self.updatedAt = [NSDate date];
}

///--------------------------------------
#pragma mark - NSFastEnumeration
///--------------------------------------
Expand Down
18 changes: 18 additions & 0 deletions Tests/Unit/OperationSetUnitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,24 @@ - (void)testRemoveObjectForKey {
XCTAssertNotEqualObjects(date, operationSet.updatedAt);
}

- (void)testRemoveAllObjects {
PFOperationSet *operationSet = [[PFOperationSet alloc] init];

operationSet[@"yarr"] = [PFSetOperation setWithValue:@"a"];
operationSet[@"yolo"] = [PFAddOperation addWithObjects:@[ @"b" ]];

XCTAssertNotNil(operationSet[@"yarr"]);
XCTAssertNotNil(operationSet[@"yolo"]);
XCTAssertEqual(operationSet.count, 2);

NSDate *date = operationSet.updatedAt;
[operationSet removeAllObjects];
XCTAssertNil(operationSet[@"yarr"]);
XCTAssertNil(operationSet[@"yolo"]);
XCTAssertEqual(operationSet.count, 0);
XCTAssertNotEqualObjects(date, operationSet.updatedAt);
}

- (void)testCopying {
PFOperationSet *operationSet = [[PFOperationSet alloc] init];
operationSet[@"yarr"] = [PFSetOperation setWithValue:@"yolo"];
Expand Down