Skip to content

Commit 889c209

Browse files
committed
Added replaceItemsAtIndexes:withItemsFromArray:
1 parent 4c8235a commit 889c209

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

Example/ExampleSSDataSources.xcodeproj/project.pbxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,6 @@
645645
baseConfigurationReference = 89D445B4C5AB7C33719C3823 /* Pods-ExampleSSDataSourcesTests.debug.xcconfig */;
646646
buildSettings = {
647647
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/ExampleSSDataSources.app/ExampleSSDataSources";
648-
FRAMEWORK_SEARCH_PATHS = "\"$(SDKROOT)/Developer/Library/Frameworks\"";
649648
GCC_PRECOMPILE_PREFIX_HEADER = YES;
650649
GCC_PREFIX_HEADER = "ExampleSSDataSources/Supporting Files/ExampleSSDataSources-Prefix.pch";
651650
INFOPLIST_FILE = "ExampleSSDataSourcesTests/Supporting Files/ExampleSSDataSourcesTests-Info.plist";
@@ -660,7 +659,6 @@
660659
baseConfigurationReference = 528C98377D5A90A3638E518A /* Pods-ExampleSSDataSourcesTests.release.xcconfig */;
661660
buildSettings = {
662661
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/ExampleSSDataSources.app/ExampleSSDataSources";
663-
FRAMEWORK_SEARCH_PATHS = "\"$(SDKROOT)/Developer/Library/Frameworks\"";
664662
GCC_PRECOMPILE_PREFIX_HEADER = YES;
665663
GCC_PREFIX_HEADER = "ExampleSSDataSources/Supporting Files/ExampleSSDataSources-Prefix.pch";
666664
INFOPLIST_FILE = "ExampleSSDataSourcesTests/Supporting Files/ExampleSSDataSourcesTests-Info.plist";

Example/ExampleSSDataSourcesTests/SSArrayDataSourceTests.m

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,43 @@ - (void)testReplaceItemsInRangeReloadsItemsInDataSourceCollectionView
313313
[mockCollectionView verify];
314314
}
315315

316+
- (void)testReplaceItemsAtIndexes
317+
{
318+
SSArrayDataSource *ds = [[SSArrayDataSource alloc] initWithItems:@[@"foo", @"baz", @"bar"]];
319+
[ds replaceItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, 2)]
320+
withItemsFromArray:@[@"iphone",@"ipad"]];
321+
expect(ds.allItems).to.equal((@[@"foo", @"iphone", @"ipad"]));
322+
}
323+
324+
- (void)testReplaceItemsAtIndexesReloadsRowsInDataSourceTableView
325+
{
326+
SSArrayDataSource *ds = [[SSArrayDataSource alloc] initWithItems:@[@"foo", @"baz", @"bar"]];
327+
id mockTableView = tableView;
328+
ds.tableView = mockTableView;
329+
330+
[[mockTableView expect] reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0], [NSIndexPath indexPathForRow:1 inSection:0]]
331+
withRowAnimation:ds.rowAnimation];
332+
333+
[ds replaceItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2)]
334+
withItemsFromArray:@[@"iphone",@"ipad"]];
335+
336+
[mockTableView verify];
337+
}
338+
339+
- (void)testReplaceItemsAtIndexesReloadsItemsInDataSourceCollectionView
340+
{
341+
SSArrayDataSource *ds = [[SSArrayDataSource alloc] initWithItems:@[@"foo", @"baz", @"bar"]];
342+
id mockCollectionView = collectionView;
343+
ds.collectionView = mockCollectionView;
344+
345+
[[mockCollectionView expect] reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0], [NSIndexPath indexPathForRow:1 inSection:0]]];
346+
347+
[ds replaceItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2)]
348+
withItemsFromArray:@[@"iphone",@"ipad"]];
349+
350+
[mockCollectionView verify];
351+
}
352+
316353
#pragma mark Removing items
317354

318355
- (void)testRemoveItemsInRange

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- Expecta (0.3.1)
2+
- Expecta (0.3.2)
33
- MagicalRecord (2.2):
44
- MagicalRecord/Core (= 2.2)
55
- MagicalRecord/Core (2.2)
@@ -17,7 +17,7 @@ EXTERNAL SOURCES:
1717
:path: ../SSDataSources.podspec
1818

1919
SPEC CHECKSUMS:
20-
Expecta: 03aabd0a89d8dea843baecb19a7fd7466a69a31d
20+
Expecta: ee641011fe10aa1855d487b40e4976dac50ec342
2121
MagicalRecord: 2b471584fc9e3137f3d0a56967917baa4979e224
2222
OCMock: ecdd510b73ef397f2f97274785c1e87fd147c49f
2323
SSDataSources: 8d5ad85657379bc60686d682f39bfdadfc89cce8

SSDataSources/SSArrayDataSource.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@
9494
*/
9595
- (void) replaceItemAtIndex:(NSUInteger)index withItem:(id)item;
9696

97+
/**
98+
* Replace items at the specified indexes with items from the provided array.
99+
*/
100+
- (void) replaceItemsAtIndexes:(NSIndexSet *)indexes withItemsFromArray:(NSArray *)array;
101+
97102
/**
98103
* Replace items in the specified range with items from the provided array.
99104
*/

SSDataSources/SSArrayDataSource.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,15 @@ - (void)insertItems:(NSArray *)newItems atIndexes:(NSIndexSet *)indexes {
168168
#pragma mark - Replacing items
169169

170170
- (void)replaceItemAtIndex:(NSUInteger)index withItem:(id)item {
171-
[self.items replaceObjectAtIndex:index withObject:item];
171+
[self replaceItemsAtIndexes:[NSIndexSet indexSetWithIndex:index] withItemsFromArray:@[ item ]];
172172
}
173173

174174
- (void)replaceItemsInRange:(NSRange)range withItemsFromArray:(NSArray *)otherArray {
175-
[self.items replaceObjectsInRange:range withObjectsFromArray:otherArray];
175+
[self replaceItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:range] withItemsFromArray:otherArray];
176+
}
177+
178+
- (void)replaceItemsAtIndexes:(NSIndexSet *)indexes withItemsFromArray:(NSArray *)array {
179+
[self.items replaceObjectsAtIndexes:indexes withObjects:array];
176180
}
177181

178182
#pragma mark - Moving Items

0 commit comments

Comments
 (0)