Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Sources/ReusableKit/ReusableKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ public struct ReusableCell<Cell: CellType> {
///
/// - parameter identifier: A reuse identifier. Use random UUID string if identifier is not provided.
/// - parameter nibName: A name of nib.
/// - parameter nibType: A type of nib.
public init(identifier: String? = nil, nibName: String) {
let nib = UINib(nibName: nibName, bundle: nil)
self.init(identifier: identifier, nib: nib)
}

public init<T>(identifier: String? = nil, nibType: T) {
let nib = UINib(nibName: String(describing: nibType.self), bundle: nil)
self.init(identifier: identifier, nib: nib)
}
}

public protocol ViewType: class {
Expand All @@ -58,9 +64,15 @@ public struct ReusableView<View: ViewType> {
///
/// - parameter identifier: A reuse identifier. Use random UUID string if identifier is not provided.
/// - parameter nibName: A name of nib.
/// - parameter nibType: A type of nib.
public init(identifier: String? = nil, nibName: String) {
let nib = UINib(nibName: nibName, bundle: nil)
self.init(identifier: identifier, nib: nib)
}

public init<T>(identifier: String? = nil, nibType: T) {
let nib = UINib(nibName: String(describing: nibType.self), bundle: nil)
self.init(identifier: identifier, nib: nib)
}
}
#endif
4 changes: 2 additions & 2 deletions Sources/ReusableKit/UITableView+ReusableKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension UITableView {

/// Returns a generic reusable cell located by its identifier.
public func dequeue<Cell>(_ cell: ReusableCell<Cell>) -> Cell? {
return self.dequeueReusableCell(withIdentifier: cell.identifier) as? Cell
return self.dequeueReusableCell(withIdentifier: cell.identifier) as! Cell
}

/// Returns a generic reusable cell located by its identifier.
Expand All @@ -40,7 +40,7 @@ extension UITableView {

/// Returns a generic reusable header of footer view located by its identifier.
public func dequeue<View>(_ view: ReusableView<View>) -> View? {
return self.dequeueReusableHeaderFooterView(withIdentifier: view.identifier) as? View
return self.dequeueReusableHeaderFooterView(withIdentifier: view.identifier) as! View
}
}
#endif