Skip to content
This repository has been archived by the owner on Jun 19, 2018. It is now read-only.

Commit

Permalink
[TAY-44]: Starts on UICollectionView conformance
Browse files Browse the repository at this point in the history
  • Loading branch information
danthorpe committed Apr 11, 2016
1 parent eb89e1e commit f5f965e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
33 changes: 31 additions & 2 deletions Sources/Conformance/Conformance.swift
Expand Up @@ -44,7 +44,6 @@ extension Int: ConfigurationIndexType {
// MARK: - UITableView

extension UITableView: ReusableCellBasedViewType {
public typealias Cell = UITableViewCell

public func registerNib(nib: UINib, withIdentifier reuseIdentifier: String) {
registerNib(nib, forCellReuseIdentifier: reuseIdentifier)
Expand All @@ -54,7 +53,7 @@ extension UITableView: ReusableCellBasedViewType {
registerClass(aClass, forCellReuseIdentifier: reuseIdentifier)
}

public func dequeueCellWithIdentifier(identifier: String, atIndex index: CellIndex) -> UITableViewCell {
public func dequeueCellWithIdentifier(identifier: String, atIndex index: NSIndexPath) -> UITableViewCell {
return dequeueReusableCellWithIdentifier(identifier, forIndexPath: index)
}
}
Expand All @@ -77,3 +76,33 @@ extension UITableView: ReusableSupplementaryViewBasedViewType {
extension UITableView: CellBasedViewType { }

// MARK: - UICollectionView

extension UICollectionView: ReusableCellBasedViewType {

public func registerNib(nib: UINib, withIdentifier reuseIdentifier: String) {
registerNib(nib, forCellWithReuseIdentifier: reuseIdentifier)
}

public func registerClass(aClass: AnyClass, withIdentifier reuseIdentifier: String) {
registerClass(aClass, forCellWithReuseIdentifier: reuseIdentifier)
}

public func dequeueCellWithIdentifier(identifier: String, atIndex index: NSIndexPath) -> UICollectionViewCell {
return dequeueReusableCellWithReuseIdentifier(identifier, forIndexPath: index)
}
}

extension UICollectionView: ReusableSupplementaryViewBasedViewType {

public func registerNib(nib: UINib, forSupplementaryViewKind kind: SupplementaryElementKind, withIdentifier reuseIdentifier: String) {
registerNib(nib, forSupplementaryViewOfKind: kind.description, withReuseIdentifier: reuseIdentifier)
}

public func registerClass(aClass: AnyClass, forSupplementaryViewKind kind: SupplementaryElementKind, withIdentifier reuseIdentifier: String) {
registerClass(aClass, forSupplementaryViewOfKind: kind.description, withReuseIdentifier: reuseIdentifier)
}

public func dequeueSupplementaryViewWithIdentifier(identifier: String, kind: SupplementaryElementKind, atIndex index: NSIndexPath) -> UICollectionReusableView? {
return dequeueReusableSupplementaryViewOfKind(kind.description, withReuseIdentifier: identifier, forIndexPath: index)
}
}
26 changes: 26 additions & 0 deletions Sources/Providers/CollectionView.swift
@@ -0,0 +1,26 @@
//
// CollectionView.swift
// TaylorSource
//
// Created by Daniel Thorpe on 11/04/2016.
// Copyright © 2016 Daniel Thorpe. All rights reserved.
//

import UIKit

/**
Providers which can create (and provide) a UICollectionViewDataSource
object should conform to this protocol.
*/
public protocol UICollectionViewDataSourceProvider {

/// - returns: an object which conforms to UICollectionViewDataSource
var collectionViewDataSource: UICollectionViewDataSource { get }
}

public protocol CollectionViewType: CellBasedViewType { }

extension UICollectionView: CollectionViewType {
public typealias CellIndex = NSIndexPath
public typealias SupplementaryIndex = NSIndexPath
}
1 change: 1 addition & 0 deletions Sources/Providers/TableView.swift
Expand Up @@ -19,6 +19,7 @@ public protocol UITableViewDataSourceProvider {
}

public protocol TableViewType: CellBasedViewType { }

extension UITableView: TableViewType {
public typealias CellIndex = NSIndexPath
public typealias SupplementaryIndex = Int
Expand Down
4 changes: 4 additions & 0 deletions TaylorSource.xcodeproj/project.pbxproj
Expand Up @@ -24,6 +24,7 @@
6590FAC01CB1819A00694DAF /* TestCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6590FABF1CB1819A00694DAF /* TestCell.xib */; };
6590FAC21CB1A2C900694DAF /* ArrayDataSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6590FAC11CB1A2C900694DAF /* ArrayDataSourceTests.swift */; };
659354491CBB76F7000FAE70 /* FetchedResultsDataSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 659354481CBB76F7000FAE70 /* FetchedResultsDataSourceTests.swift */; };
6593544B1CBC1959000FAE70 /* CollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6593544A1CBC1959000FAE70 /* CollectionView.swift */; };
65B9E08A1CB9AB1D009161AD /* CellDataSourceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B9E0891CB9AB1D009161AD /* CellDataSourceType.swift */; };
65B9E08F1CB9BB59009161AD /* TableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B9E08E1CB9BB59009161AD /* TableView.swift */; };
65E3FC731CBA64CD00479E0C /* IndexType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65E3FC721CBA64CD00479E0C /* IndexType.swift */; };
Expand Down Expand Up @@ -66,6 +67,7 @@
6590FABF1CB1819A00694DAF /* TestCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TestCell.xib; sourceTree = "<group>"; };
6590FAC11CB1A2C900694DAF /* ArrayDataSourceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayDataSourceTests.swift; sourceTree = "<group>"; };
659354481CBB76F7000FAE70 /* FetchedResultsDataSourceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedResultsDataSourceTests.swift; sourceTree = "<group>"; };
6593544A1CBC1959000FAE70 /* CollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CollectionView.swift; path = Providers/CollectionView.swift; sourceTree = "<group>"; };
65B9E0891CB9AB1D009161AD /* CellDataSourceType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellDataSourceType.swift; sourceTree = "<group>"; };
65B9E08E1CB9BB59009161AD /* TableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TableView.swift; path = Providers/TableView.swift; sourceTree = "<group>"; };
65E3FC721CBA64CD00479E0C /* IndexType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IndexType.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -190,6 +192,7 @@
isa = PBXGroup;
children = (
65B9E08E1CB9BB59009161AD /* TableView.swift */,
6593544A1CBC1959000FAE70 /* CollectionView.swift */,
);
name = Providers;
sourceTree = "<group>";
Expand Down Expand Up @@ -310,6 +313,7 @@
650849841CB15C50005C7E6F /* Conformance.swift in Sources */,
65E3FC731CBA64CD00479E0C /* IndexType.swift in Sources */,
65B9E08F1CB9BB59009161AD /* TableView.swift in Sources */,
6593544B1CBC1959000FAE70 /* CollectionView.swift in Sources */,
650849891CB15C50005C7E6F /* DataSourceType.swift in Sources */,
65E3FC751CBA853200479E0C /* FetchedResultsDataSource.swift in Sources */,
650849861CB15C50005C7E6F /* Factory.swift in Sources */,
Expand Down

0 comments on commit f5f965e

Please sign in to comment.