From 8104b26dbbfd1d7fc853da45d5e9ca78f0402c5b Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Tue, 26 Jul 2016 17:55:39 +0300 Subject: [PATCH] some more code --- LeadKit/LeadKit.xcodeproj/project.pbxproj | 16 ++++++++ .../Classes/Cache/ViewsGenerator.swift | 4 +- .../Controllers/TableViewController.swift | 38 +++++++++++++++---- LeadKit/LeadKit/Enums/CellCreationType.swift | 22 +++++++++++ .../UIView/UIView+DefaultNibName.swift | 2 +- .../UIView+DefaultReuseIdentifier.swift | 22 +++++++++++ 6 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 LeadKit/LeadKit/Enums/CellCreationType.swift create mode 100644 LeadKit/LeadKit/Extensions/UIView/UIView+DefaultReuseIdentifier.swift diff --git a/LeadKit/LeadKit.xcodeproj/project.pbxproj b/LeadKit/LeadKit.xcodeproj/project.pbxproj index fa8dfb3a..2665126f 100644 --- a/LeadKit/LeadKit.xcodeproj/project.pbxproj +++ b/LeadKit/LeadKit.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 78011A641D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78011A631D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift */; }; + 78011A691D47AF5100EA16A2 /* CellCreationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78011A681D47AF5100EA16A2 /* CellCreationType.swift */; }; 7824CA521CFEE6B700D7B132 /* UIImage+RenderTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7824CA511CFEE6B700D7B132 /* UIImage+RenderTemplate.swift */; }; 7837F60F1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7837F60E1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift */; }; 785C33451CFC908800C4C4AA /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 785C33441CFC908800C4C4AA /* TableViewController.swift */; }; @@ -49,6 +51,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 78011A631D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+DefaultReuseIdentifier.swift"; sourceTree = ""; }; + 78011A681D47AF5100EA16A2 /* CellCreationType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellCreationType.swift; sourceTree = ""; }; 7824CA511CFEE6B700D7B132 /* UIImage+RenderTemplate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+RenderTemplate.swift"; sourceTree = ""; }; 7837F60E1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EstimatedViewHeightProtocol.swift; sourceTree = ""; }; 785C33441CFC908800C4C4AA /* TableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; @@ -103,6 +107,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 78011A651D47AF3000EA16A2 /* Enums */ = { + isa = PBXGroup; + children = ( + 78011A681D47AF5100EA16A2 /* CellCreationType.swift */, + ); + path = Enums; + sourceTree = ""; + }; 7830C4131C6B336A00180D02 /* Frameworks */ = { isa = PBXGroup; children = ( @@ -180,6 +192,7 @@ 7830C4131C6B336A00180D02 /* Frameworks */, 78A74EAA1C6B401800FE9724 /* Classes */, 78CFEE441C5C45E500F50370 /* Extensions */, + 78011A651D47AF3000EA16A2 /* Enums */, 78CFEE491C5C45E500F50370 /* Protocols */, 78CFEE2D1C5C456B00F50370 /* LeadKit.h */, 78CFEE2F1C5C456B00F50370 /* Info.plist */, @@ -249,6 +262,7 @@ children = ( 78CFEE481C5C45E500F50370 /* UIView+LoadFromNib.swift */, 78A74EA81C6B373700FE9724 /* UIView+DefaultNibName.swift */, + 78011A631D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift */, ); path = UIView; sourceTree = ""; @@ -427,6 +441,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 78011A691D47AF5100EA16A2 /* CellCreationType.swift in Sources */, 785C33451CFC908800C4C4AA /* TableViewController.swift in Sources */, 7837F60F1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift in Sources */, 78CFEE541C5C45E500F50370 /* UIView+LoadFromNib.swift in Sources */, @@ -435,6 +450,7 @@ 78CFEE571C5C45E500F50370 /* StaticNibNameProtocol.swift in Sources */, 788EC15A1CF64528009CFB6B /* UIStoryboard+InstantiateViewController.swift in Sources */, 787783671CA04D4A001CDC9B /* NSString+SizeCalculation.swift in Sources */, + 78011A641D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift in Sources */, 78CFEE531C5C45E500F50370 /* UITableView+DequeueCustomCell.swift in Sources */, 78E59B1B1C77470A00C6BFE9 /* ViewsGenerator.swift in Sources */, 78B0FC811C6B2CD500358B64 /* App.swift in Sources */, diff --git a/LeadKit/LeadKit/Classes/Cache/ViewsGenerator.swift b/LeadKit/LeadKit/Classes/Cache/ViewsGenerator.swift index 8d1de582..352bc3de 100644 --- a/LeadKit/LeadKit/Classes/Cache/ViewsGenerator.swift +++ b/LeadKit/LeadKit/Classes/Cache/ViewsGenerator.swift @@ -19,9 +19,7 @@ public class ViewsGenerator: ObjectsGenerator { - returns: nothing */ init(poolSize: UInt, nibName: String) { - super.init(poolSize: poolSize, objectsContructor: {() -> T in - T.loadFromNib(named: nibName) - }) + super.init(poolSize: poolSize, objectsContructor: { T.loadFromNib(named: nibName) }) } } diff --git a/LeadKit/LeadKit/Controllers/TableViewController.swift b/LeadKit/LeadKit/Controllers/TableViewController.swift index 4abee065..a2d202a9 100644 --- a/LeadKit/LeadKit/Controllers/TableViewController.swift +++ b/LeadKit/LeadKit/Controllers/TableViewController.swift @@ -8,14 +8,7 @@ import UIKit -public enum CellCreationType: Int { - - case Preloaded = 0 - case OnTheFlight = 1 - -} - -public class TableViewController: UITableViewController, CellsControllerProtocol { +public class TableViewController: UITableViewController, CellsControllerProtocol { private var heightCache: [NSIndexPath: CGFloat] = [:] @@ -50,6 +43,12 @@ public class TableViewController: UITableViewController, CellsControllerProtocol aCoder.encodeInteger(cellCreationType.rawValue, forKey: "CellCreationType") } + /** + method which adds cells generator for cells with specified reuse identifier + + - parameter cellsGenerator: cells generator + - parameter cellIdentifier: cell reuse identifier + */ public func registerCellsGenerator(cellsGenerator: ViewsGenerator, forCellsWithIdentifier cellIdentifier: String) { cellsObjectsCreators[cellIdentifier] = cellsGenerator @@ -97,20 +96,43 @@ public class TableViewController: UITableViewController, CellsControllerProtocol // MARK: - Cache + /** + method which invalidates cache + */ public func invalidateCache() { heightCache = [:] } // MARK: - Cells сontroller stub implementation + /** + method which returns reuse identifier for cell at specified index path + + - parameter indexPath: NSIndexPath object + + - returns: reuse identifier + */ public func cellIdentifierForIndexPath(indexPath: NSIndexPath) -> String { fatalError("Your should implement cellIdentifierForIndexPath(_:)") } + /** + method which configures cell before it can be used + + - parameter cell: UITableView or subclass cell + - parameter atIndexPath: index path of cell + */ public func configureCell(cell: UITableViewCell, atIndexPath: NSIndexPath) { // intended to be implemented in subclasses } + /** + method which return height for cell at specified index path + + - parameter indexPath: NSIndexPath object + + - returns: height of cell at specified index path + */ public func heightForCellAtIndexPath(indexPath: NSIndexPath) -> CGFloat { // intended to be implemented in subclasses return UITableViewAutomaticDimension diff --git a/LeadKit/LeadKit/Enums/CellCreationType.swift b/LeadKit/LeadKit/Enums/CellCreationType.swift new file mode 100644 index 00000000..a2d09dbf --- /dev/null +++ b/LeadKit/LeadKit/Enums/CellCreationType.swift @@ -0,0 +1,22 @@ +// +// CellCreationType.swift +// LeadKit +// +// Created by Ivan Smolin on 26/07/16. +// Copyright © 2016 Touch Instinct. All rights reserved. +// + +import Foundation + +/** + enum which describes cell creation behaviour of CellsControllerProtocol + + - Preloaded: cells is generated in advance + - OnTheFlight: cells is created on demand + */ +public enum CellCreationType: Int { + + case Preloaded = 0 + case OnTheFlight = 1 + +} diff --git a/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultNibName.swift b/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultNibName.swift index 25d38eff..0ec6d6f5 100644 --- a/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultNibName.swift +++ b/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultNibName.swift @@ -16,7 +16,7 @@ extension UIView: StaticNibNameProtocol { */ public class func nibName() -> String { - return NSStringFromClass(self).componentsSeparatedByString(".").last! + return String(self.dynamicType).componentsSeparatedByString(".").last! } } diff --git a/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultReuseIdentifier.swift b/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultReuseIdentifier.swift new file mode 100644 index 00000000..1527d546 --- /dev/null +++ b/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultReuseIdentifier.swift @@ -0,0 +1,22 @@ +// +// UIView+DefaultReuseIdentifier.swift +// LeadKit +// +// Created by Ivan Smolin on 26/07/16. +// Copyright © 2016 Touch Instinct. All rights reserved. +// + +import UIKit + +extension UIView: ReuseIdentifierProtocol { + + /** + default implementation of ReuseIdentifierProtocol + + - returns: type name string + */ + public class func reuseIdentifier() -> String { + return String(self.dynamicType) + } + +}