Skip to content

Commit

Permalink
rename object wording to read - item.
Browse files Browse the repository at this point in the history
  • Loading branch information
DenTelezhkin committed Oct 11, 2015
1 parent 19ae833 commit 602da44
Showing 1 changed file with 74 additions and 10 deletions.
84 changes: 74 additions & 10 deletions DTCollectionViewManager/DTCollectionViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T:ModelTransfer where T:UICollectionViewCell>(cell:T?) -> T.ModelType?
/// - SeeAlso: `StorageProtocol` method `itemForCellClass:atIndexPath:` - will return model even if cell is not visible
public func itemForVisibleCell<T:ModelTransfer where T:UICollectionViewCell>(cell:T?) -> T.ModelType?
{
guard cell != nil else { return nil }

Expand All @@ -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<T:ModelTransfer where T:UICollectionViewCell>(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<T:ModelTransfer where T:UICollectionViewCell>(cellClass: T.Type, atIndexPath indexPath: NSIndexPath) -> T.ModelType?
{
return self.storage.itemForCellClass(T.self, atIndexPath: indexPath)
}
Expand All @@ -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<T:ModelTransfer where T:UICollectionReusableView>(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<T:ModelTransfer where T:UICollectionReusableView>(headerClass: T.Type, atSectionIndex sectionIndex: Int) -> T.ModelType?
{
return self.storage.itemForHeaderClass(T.self, atSectionIndex: sectionIndex)
}
Expand All @@ -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<T:ModelTransfer where T:UICollectionReusableView>(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<T:ModelTransfer where T:UICollectionReusableView>(footerClass: T.Type, atSectionIndex sectionIndex: Int) -> T.ModelType?
{
return self.storage.itemForFooterClass(T.self, atSectionIndex: sectionIndex)
}
Expand All @@ -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<T:ModelTransfer where T:UICollectionReusableView>(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<T:ModelTransfer where T:UICollectionReusableView>(supplementaryClass: T.Type, ofKind kind: String, atSectionIndex sectionIndex: Int) -> T.ModelType?
{
return (self.storage as? SupplementaryStorageProtocol)?.supplementaryModelOfKind(kind, sectionIndex: sectionIndex) as? T.ModelType
}
Expand Down Expand Up @@ -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<T:ModelTransfer where T:UICollectionViewCell>(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<T:ModelTransfer where T:UICollectionViewCell>(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<T:ModelTransfer where T:UICollectionReusableView>(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<T:ModelTransfer where T:UICollectionReusableView>(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<T:ModelTransfer where T:UICollectionReusableView>(supplementaryClass: T.Type, ofKind kind: String, atSectionIndex sectionIndex: Int) -> T.ModelType?
{
return (self.storage as? SupplementaryStorageProtocol)?.supplementaryModelOfKind(kind, sectionIndex: sectionIndex) as? T.ModelType
}
}

0 comments on commit 602da44

Please sign in to comment.