Skip to content

Commit

Permalink
add insert section method, bump podspec
Browse files Browse the repository at this point in the history
  • Loading branch information
DenTelezhkin committed Oct 11, 2015
1 parent 1c34b65 commit e58a324
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Change Log
All notable changes to this project will be documented in this file.

## [2.1.1](https://github.com/DenHeadless/DTModelStorage/releases/tag/2.1.1)

#### Added
* `insertSection(_:atIndex:)` that allows to insert `SectionModel` directly, with items and supplementary headers.

## [2.1.0](https://github.com/DenHeadless/DTModelStorage/releases/tag/2.1.0)

#### Updated
* `StorageUpdate` class was rewritten from scratch using Swift `Set`.
* `StorageUpdate` now contains `movedRowIndexPaths` and `movedSectionIndexes` properties.
* `StorageUpdate` class was rewritten from scratch using Swift Set.
* `StorageUpdate` now contains movedRowIndexPaths and movedSectionIndexes properties
* All method names and properties, that contained `object` term in their name, have been renamed to read 'item' instead

#### Fixed
* `removeItems` method should no longer skip items, if their indexPath is reduced when removing previous item
Expand All @@ -16,7 +22,6 @@ All notable changes to this project will be documented in this file.
* `moveCollectionViewSection:toSection` and `moveTableViewSection:toSection` have been replaced by `moveSection:toSection` method

## [2.0.0](https://github.com/DenHeadless/DTModelStorage/releases/tag/2.0.0)
Released on 2015-09-13.

Framework was completely rewritten from scratch in Swift 2.

Expand Down
2 changes: 1 addition & 1 deletion DTModelStorage.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'DTModelStorage'
s.version = '2.1.0'
s.version = '2.1.1'
s.license = 'MIT'
s.summary = 'Storage classes for datasource based controls.'
s.homepage = 'https://github.com/DenHeadless/DTModelStorage'
Expand Down
14 changes: 14 additions & 0 deletions DTModelStorage/Memory/MemoryStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ public class MemoryStorage: BaseStorage, StorageProtocol
self.delegate?.storageNeedsReloading()
}

/// Insert section. This method is assumed to be used, when you need to insert section with items and supplementaries in one batch operation. If you need to simply add items, use `addItems` or `setItems` instead.
/// - Parameter section: section to insert
/// - Parameter atIndex: index of section to insert. If `atIndex` is larger than number of sections, method does nothing.
public func insertSection(section: SectionModel, atIndex sectionIndex: Int) {
guard sectionIndex <= sections.count else { return }
startUpdate()
sections.insert(section, atIndex: sectionIndex)
currentUpdate?.insertedSectionIndexes.insert(sectionIndex)
for item in 0..<section.numberOfItems {
currentUpdate?.insertedRowIndexPaths.insert(NSIndexPath(forItem: item, inSection: sectionIndex))
}
finishUpdate()
}

/// Add items to section with `toSection` number.
/// - Parameter items: items to add
/// - Parameter toSection: index of section to add items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,13 @@ class MemoryStorageEditSpecs: XCTestCase {
class SectionSupplementariesTestCase : XCTestCase
{
var storage : MemoryStorage!

var updatesObserver : StorageUpdatesObserver!
override func setUp() {
super.setUp()
self.storage = MemoryStorage()
self.storage.configureForTableViewUsage()
updatesObserver = StorageUpdatesObserver()
storage.delegate = updatesObserver
}

func testSectionHeaderModelsSetter()
Expand Down Expand Up @@ -382,4 +384,28 @@ class SectionSupplementariesTestCase : XCTestCase

expect(self.storage.footerModelForSectionIndex(1) as? Int).to(beNil())
}

func testInsertingSection()
{
let section = SectionModel()
section.setSupplementaryModel("Foo", forKind: UICollectionElementKindSectionHeader)
section.setSupplementaryModel("Bar", forKind: UICollectionElementKindSectionFooter)
section.items = [1,2,3]
storage.insertSection(section, atIndex: 0)

expect(self.updatesObserver.update?.insertedSectionIndexes) == Set([0])
expect(self.updatesObserver.update?.insertedRowIndexPaths) == Set([indexPath(0, 0),indexPath(1, 0),indexPath(2, 0)])

expect(self.storage.sectionAtIndex(0)?.supplementaryModelOfKind(UICollectionElementKindSectionHeader) as? String) == "Foo"
expect(self.storage.sectionAtIndex(0)?.supplementaryModelOfKind(UICollectionElementKindSectionFooter) as? String) == "Bar"
expect(self.storage.sectionAtIndex(0)?.items.first as? Int) == 1
expect(self.storage.sectionAtIndex(0)?.items.last as? Int) == 3
}

func testInsertingSectionAtWrongIndexPathDoesNotWork()
{
let section = SectionModel()

storage.insertSection(section, atIndex: 1)
}
}

0 comments on commit e58a324

Please sign in to comment.