diff --git a/DTCollectionViewManager/DTCollectionViewManager.swift b/DTCollectionViewManager/DTCollectionViewManager.swift index 2323e87..5c80a31 100644 --- a/DTCollectionViewManager/DTCollectionViewManager.swift +++ b/DTCollectionViewManager/DTCollectionViewManager.swift @@ -140,8 +140,8 @@ public class DTCollectionViewManager : NSObject { /// Call this method to retrieve model from specific UICollectionViewCell subclass. /// - Note: This method uses UICollectionView `indexPathForCell` method, that returns nil if cell is not visible. Therefore, if cell is not visible, this method will return nil as well. - /// - SeeAlso: `StorageProtocol` method `objectForCell:atIndexPath:` - will return model even if cell is not visible - public func objectForVisibleCell(cell:T?) -> T.ModelType? + /// - SeeAlso: `StorageProtocol` method `itemForCellClass:atIndexPath:` - will return model even if cell is not visible + public func itemForVisibleCell(cell:T?) -> T.ModelType? { guard cell != nil else { return nil } @@ -155,8 +155,8 @@ public class DTCollectionViewManager : NSObject { /// - Parameter cellClass: UICollectionViewCell type /// - Parameter indexPath: NSIndexPath of the data model /// - Returns: data model that belongs to this index path. - /// - Note: Method does not require cell to be visible, however it requires that storage really contains object of `ModelType` at specified index path, otherwise it will return nil. - public func objectForCellClass(cellClass: T.Type, atIndexPath indexPath: NSIndexPath) -> T.ModelType? + /// - Note: Method does not require cell to be visible, however it requires that storage really contains item of `ModelType` at specified index path, otherwise it will return nil. + public func itemForCellClass(cellClass: T.Type, atIndexPath indexPath: NSIndexPath) -> T.ModelType? { return self.storage.itemForCellClass(T.self, atIndexPath: indexPath) } @@ -165,8 +165,8 @@ public class DTCollectionViewManager : NSObject { /// - Parameter headerClass: UICollectionReusableView type /// - Parameter indexPath: NSIndexPath of the view /// - Returns: data model that belongs to this view - /// - Note: Method does not require header to be visible, however it requires that storage really contains object of `ModelType` at specified section index, and storage to comply to `HeaderFooterStorageProtocol`, otherwise it will return nil. - public func objectForHeaderClass(headerClass: T.Type, atSectionIndex sectionIndex: Int) -> T.ModelType? + /// - Note: Method does not require header to be visible, however it requires that storage really contains item of `ModelType` at specified section index, and storage to comply to `HeaderFooterStorageProtocol`, otherwise it will return nil. + public func itemForHeaderClass(headerClass: T.Type, atSectionIndex sectionIndex: Int) -> T.ModelType? { return self.storage.itemForHeaderClass(T.self, atSectionIndex: sectionIndex) } @@ -175,8 +175,8 @@ public class DTCollectionViewManager : NSObject { /// - Parameter footerClass: UICollectionReusableView type /// - Parameter indexPath: NSIndexPath of the view /// - Returns: data model that belongs to this view - /// - Note: Method does not require footer to be visible, however it requires that storage really contains object of `ModelType` at specified section index, and storage to comply to `HeaderFooterStorageProtocol`, otherwise it will return nil. - public func objectForFooterClass(footerClass: T.Type, atSectionIndex sectionIndex: Int) -> T.ModelType? + /// - Note: Method does not require footer to be visible, however it requires that storage really contains item of `ModelType` at specified section index, and storage to comply to `HeaderFooterStorageProtocol`, otherwise it will return nil. + public func itemForFooterClass(footerClass: T.Type, atSectionIndex sectionIndex: Int) -> T.ModelType? { return self.storage.itemForFooterClass(T.self, atSectionIndex: sectionIndex) } @@ -186,8 +186,8 @@ public class DTCollectionViewManager : NSObject { /// - Parameter kind: supplementary kind /// - Parameter atSectionIndex: NSIndexPath of the view /// - Returns: data model that belongs to this view - /// - Note: Method does not require supplementary view to be visible, however it requires that storage really contains object of `ModelType` at specified section index, and storage to comply to `SupplementaryStorageProcotol`, otherwise it will return nil. - public func objectForSupplementaryClass(supplementaryClass: T.Type, ofKind kind: String, atSectionIndex sectionIndex: Int) -> T.ModelType? + /// - Note: Method does not require supplementary view to be visible, however it requires that storage really contains item of `ModelType` at specified section index, and storage to comply to `SupplementaryStorageProcotol`, otherwise it will return nil. + public func itemForSupplementaryClass(supplementaryClass: T.Type, ofKind kind: String, atSectionIndex sectionIndex: Int) -> T.ModelType? { return (self.storage as? SupplementaryStorageProtocol)?.supplementaryModelOfKind(kind, sectionIndex: sectionIndex) as? T.ModelType } @@ -628,4 +628,68 @@ extension DTCollectionViewManager : CollectionViewStorageUpdating public func performAnimatedUpdate(block: (UICollectionView) -> Void) { block(collectionView) } +} + + +// MARK: - DEPRECATED +extension DTCollectionViewManager +{ + /// Call this method to retrieve model from specific UICollectionViewCell subclass. + /// - Note: This method uses UICollectionView `indexPathForCell` method, that returns nil if cell is not visible. Therefore, if cell is not visible, this method will return nil as well. + /// - SeeAlso: `StorageProtocol` method `objectForCell:atIndexPath:` - will return model even if cell is not visible + @available(*, unavailable, renamed="itemForVisibleCell") + public func objectForVisibleCell(cell:T?) -> T.ModelType? + { + guard cell != nil else { return nil } + + if let indexPath = self.collectionView.indexPathForCell(cell!) { + return storage.itemAtIndexPath(indexPath) as? T.ModelType + } + return nil + } + + /// Retrieve model of specific type at index path. + /// - Parameter cellClass: UICollectionViewCell type + /// - Parameter indexPath: NSIndexPath of the data model + /// - Returns: data model that belongs to this index path. + /// - Note: Method does not require cell to be visible, however it requires that storage really contains object of `ModelType` at specified index path, otherwise it will return nil. + @available(*, unavailable, renamed="itemForCellClass") + public func objectForCellClass(cellClass: T.Type, atIndexPath indexPath: NSIndexPath) -> T.ModelType? + { + return self.storage.itemForCellClass(T.self, atIndexPath: indexPath) + } + + /// Retrieve model of specific type for section index. + /// - Parameter headerClass: UICollectionReusableView type + /// - Parameter indexPath: NSIndexPath of the view + /// - Returns: data model that belongs to this view + /// - Note: Method does not require header to be visible, however it requires that storage really contains object of `ModelType` at specified section index, and storage to comply to `HeaderFooterStorageProtocol`, otherwise it will return nil. + @available(*,unavailable,renamed="itemForHeaderClass") + public func objectForHeaderClass(headerClass: T.Type, atSectionIndex sectionIndex: Int) -> T.ModelType? + { + return self.storage.itemForHeaderClass(T.self, atSectionIndex: sectionIndex) + } + + /// Retrieve model of specific type for section index. + /// - Parameter footerClass: UICollectionReusableView type + /// - Parameter indexPath: NSIndexPath of the view + /// - Returns: data model that belongs to this view + /// - Note: Method does not require footer to be visible, however it requires that storage really contains object of `ModelType` at specified section index, and storage to comply to `HeaderFooterStorageProtocol`, otherwise it will return nil. + @available(*,unavailable,renamed="itemForFooterClass") + public func objectForFooterClass(footerClass: T.Type, atSectionIndex sectionIndex: Int) -> T.ModelType? + { + return self.storage.itemForFooterClass(T.self, atSectionIndex: sectionIndex) + } + + /// Retrieve model of specific type for section index. + /// - Parameter supplementaryClass: UICollectionReusableView type + /// - Parameter kind: supplementary kind + /// - Parameter atSectionIndex: NSIndexPath of the view + /// - Returns: data model that belongs to this view + /// - Note: Method does not require supplementary view to be visible, however it requires that storage really contains object of `ModelType` at specified section index, and storage to comply to `SupplementaryStorageProcotol`, otherwise it will return nil. + @available(*,unavailable,renamed="itemForSupplementaryClass") + public func objectForSupplementaryClass(supplementaryClass: T.Type, ofKind kind: String, atSectionIndex sectionIndex: Int) -> T.ModelType? + { + return (self.storage as? SupplementaryStorageProtocol)?.supplementaryModelOfKind(kind, sectionIndex: sectionIndex) as? T.ModelType + } } \ No newline at end of file