From bd636a8fc3d76370cefba136140184bb0d35e921 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 3 Oct 2016 15:33:43 +0300 Subject: [PATCH 1/5] update RxAlamofire version in podspec --- LeadKit.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LeadKit.podspec b/LeadKit.podspec index e8bec314..bf1736d6 100644 --- a/LeadKit.podspec +++ b/LeadKit.podspec @@ -15,5 +15,5 @@ Pod::Spec.new do |s| s.dependency "RxSwift", '~> 2.6' s.dependency "RxCocoa", '~> 2.6' s.dependency "Alamofire", '~> 3.4' - s.dependency "RxAlamofire", '~> 1.1' + s.dependency "RxAlamofire", '~> 2.5' end From 89b8dfe7c2f0480193a452935da2d334b59462ee Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Tue, 4 Oct 2016 17:48:37 +0300 Subject: [PATCH 2/5] delete abandoned table controller code --- LeadKit/LeadKit.xcodeproj/project.pbxproj | 37 ------ .../Classes/Cache/ObjectsGenerator.swift | 57 --------- .../Classes/Cache/ViewsGenerator.swift | 23 ---- .../Controllers/TableViewController.swift | 109 ------------------ LeadKit/LeadKit/Enums/CellCreationType.swift | 22 ---- .../Protocols/CellsControllerProtocol.swift | 36 ------ 6 files changed, 284 deletions(-) delete mode 100644 LeadKit/LeadKit/Classes/Cache/ObjectsGenerator.swift delete mode 100644 LeadKit/LeadKit/Classes/Cache/ViewsGenerator.swift delete mode 100644 LeadKit/LeadKit/Controllers/TableViewController.swift delete mode 100644 LeadKit/LeadKit/Enums/CellCreationType.swift delete mode 100644 LeadKit/LeadKit/Protocols/CellsControllerProtocol.swift diff --git a/LeadKit/LeadKit.xcodeproj/project.pbxproj b/LeadKit/LeadKit.xcodeproj/project.pbxproj index fc5b240d..7137581a 100644 --- a/LeadKit/LeadKit.xcodeproj/project.pbxproj +++ b/LeadKit/LeadKit.xcodeproj/project.pbxproj @@ -13,11 +13,9 @@ 0A3BB9721D5DCFE100B03CBD /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0A3BB96E1D5DCFE100B03CBD /* RxSwift.framework */; }; 0A3BB9741D5DCFEC00B03CBD /* RxCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0A3BB9731D5DCFEC00B03CBD /* RxCocoa.framework */; }; 78011A641D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78011A631D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift */; }; - 78011A691D47AF5100EA16A2 /* CellCreationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78011A681D47AF5100EA16A2 /* CellCreationType.swift */; }; 78011AB31D48B53600EA16A2 /* ApiRequestParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78011AB21D48B53600EA16A2 /* ApiRequestParameters.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 */; }; 786A17A11CB8D71D007F9661 /* UIImage+CapInsetsUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 786A17A01CB8D71D007F9661 /* UIImage+CapInsetsUtils.swift */; }; 786D78E81D53C378006B2CEA /* AlamofireRequest+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 786D78E71D53C378006B2CEA /* AlamofireRequest+Extensions.swift */; }; 786D78EA1D53C43E006B2CEA /* ApiError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 786D78E91D53C43E006B2CEA /* ApiError.swift */; }; @@ -25,7 +23,6 @@ 787682FA1CAD40C300532AB3 /* StaticEstimatedViewHeightProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787682F91CAD40C200532AB3 /* StaticEstimatedViewHeightProtocol.swift */; }; 787783631CA03CA0001CDC9B /* NSIndexPath+ImmutableIndexPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787783621CA03CA0001CDC9B /* NSIndexPath+ImmutableIndexPath.swift */; }; 787783671CA04D4A001CDC9B /* String+SizeCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787783661CA04D4A001CDC9B /* String+SizeCalculation.swift */; }; - 787A071A1D085750009EC97F /* CellsControllerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787A07191D085750009EC97F /* CellsControllerProtocol.swift */; }; 788EC15A1CF64528009CFB6B /* UIStoryboard+InstantiateViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 788EC1591CF64528009CFB6B /* UIStoryboard+InstantiateViewController.swift */; }; 78A74EA91C6B373700FE9724 /* UIView+DefaultNibName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78A74EA81C6B373700FE9724 /* UIView+DefaultNibName.swift */; }; 78B0FC7D1C6B2BE200358B64 /* LogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B0FC7C1C6B2BE200358B64 /* LogFormatter.swift */; }; @@ -49,8 +46,6 @@ 78CFEE591C5C45E500F50370 /* StoryboardIdentifierProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78CFEE4E1C5C45E500F50370 /* StoryboardIdentifierProtocol.swift */; }; 78CFEE5A1C5C45E500F50370 /* ViewHeightProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78CFEE4F1C5C45E500F50370 /* ViewHeightProtocol.swift */; }; 78CFEE5B1C5C45E500F50370 /* ViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78CFEE501C5C45E500F50370 /* ViewModelProtocol.swift */; }; - 78E59B191C773EE600C6BFE9 /* ObjectsGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E59B181C773EE600C6BFE9 /* ObjectsGenerator.swift */; }; - 78E59B1B1C77470A00C6BFE9 /* ViewsGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78E59B1A1C77470A00C6BFE9 /* ViewsGenerator.swift */; }; 95B39A781D9BFCC30057BD54 /* UIImageView+LoadingImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B39A771D9BFCC30057BD54 /* UIImageView+LoadingImage.swift */; }; 95B39A7A1D9BFD550057BD54 /* UIImage+Loading.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B39A791D9BFD550057BD54 /* UIImage+Loading.swift */; }; 95B39A7C1D9C05260057BD54 /* UIImage+Gradients.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B39A7B1D9C05260057BD54 /* UIImage+Gradients.swift */; }; @@ -77,11 +72,9 @@ 0A3BB96E1D5DCFE100B03CBD /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = RxSwift.framework; sourceTree = ""; }; 0A3BB9731D5DCFEC00B03CBD /* RxCocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = RxCocoa.framework; sourceTree = ""; }; 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 = ""; }; 78011AB21D48B53600EA16A2 /* ApiRequestParameters.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApiRequestParameters.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 = ""; }; 786A17A01CB8D71D007F9661 /* UIImage+CapInsetsUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+CapInsetsUtils.swift"; sourceTree = ""; }; 786D78E71D53C378006B2CEA /* AlamofireRequest+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AlamofireRequest+Extensions.swift"; sourceTree = ""; }; 786D78E91D53C43E006B2CEA /* ApiError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApiError.swift; sourceTree = ""; }; @@ -89,7 +82,6 @@ 787682F91CAD40C200532AB3 /* StaticEstimatedViewHeightProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StaticEstimatedViewHeightProtocol.swift; sourceTree = ""; }; 787783621CA03CA0001CDC9B /* NSIndexPath+ImmutableIndexPath.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSIndexPath+ImmutableIndexPath.swift"; sourceTree = ""; }; 787783661CA04D4A001CDC9B /* String+SizeCalculation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+SizeCalculation.swift"; sourceTree = ""; }; - 787A07191D085750009EC97F /* CellsControllerProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellsControllerProtocol.swift; sourceTree = ""; }; 788EC1591CF64528009CFB6B /* UIStoryboard+InstantiateViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIStoryboard+InstantiateViewController.swift"; sourceTree = ""; }; 78A74EA81C6B373700FE9724 /* UIView+DefaultNibName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIView+DefaultNibName.swift"; path = "LeadKit/Extensions/UIView/UIView+DefaultNibName.swift"; sourceTree = SOURCE_ROOT; }; 78B0FC7C1C6B2BE200358B64 /* LogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogFormatter.swift; sourceTree = ""; }; @@ -116,8 +108,6 @@ 78CFEE4E1C5C45E500F50370 /* StoryboardIdentifierProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardIdentifierProtocol.swift; sourceTree = ""; }; 78CFEE4F1C5C45E500F50370 /* ViewHeightProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewHeightProtocol.swift; sourceTree = ""; }; 78CFEE501C5C45E500F50370 /* ViewModelProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewModelProtocol.swift; sourceTree = ""; }; - 78E59B181C773EE600C6BFE9 /* ObjectsGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectsGenerator.swift; sourceTree = ""; }; - 78E59B1A1C77470A00C6BFE9 /* ViewsGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewsGenerator.swift; sourceTree = ""; }; 95B39A771D9BFCC30057BD54 /* UIImageView+LoadingImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIImageView+LoadingImage.swift"; path = "UIImageView/UIImageView+LoadingImage.swift"; sourceTree = ""; }; 95B39A791D9BFD550057BD54 /* UIImage+Loading.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Loading.swift"; sourceTree = ""; }; 95B39A7B1D9C05260057BD54 /* UIImage+Gradients.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Gradients.swift"; sourceTree = ""; }; @@ -166,7 +156,6 @@ 78011A651D47AF3000EA16A2 /* Enums */ = { isa = PBXGroup; children = ( - 78011A681D47AF5100EA16A2 /* CellCreationType.swift */, 786D78E91D53C43E006B2CEA /* ApiError.swift */, ); path = Enums; @@ -188,15 +177,6 @@ path = Api; sourceTree = ""; }; - 785C33431CFC89EF00C4C4AA /* Controllers */ = { - isa = PBXGroup; - children = ( - 785C33441CFC908800C4C4AA /* TableViewController.swift */, - ); - name = Controllers; - path = ../Controllers; - sourceTree = ""; - }; 786D78E61D53C355006B2CEA /* Alamofire */ = { isa = PBXGroup; children = ( @@ -226,8 +206,6 @@ 78A74EAA1C6B401800FE9724 /* Classes */ = { isa = PBXGroup; children = ( - 785C33431CFC89EF00C4C4AA /* Controllers */, - 78E59B171C773E9600C6BFE9 /* Cache */, 78B0FC7B1C6B2BAE00358B64 /* Logging */, ); path = Classes; @@ -330,20 +308,10 @@ 78CFEE501C5C45E500F50370 /* ViewModelProtocol.swift */, 787682F91CAD40C200532AB3 /* StaticEstimatedViewHeightProtocol.swift */, 7837F60E1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift */, - 787A07191D085750009EC97F /* CellsControllerProtocol.swift */, ); path = Protocols; sourceTree = ""; }; - 78E59B171C773E9600C6BFE9 /* Cache */ = { - isa = PBXGroup; - children = ( - 78E59B181C773EE600C6BFE9 /* ObjectsGenerator.swift */, - 78E59B1A1C77470A00C6BFE9 /* ViewsGenerator.swift */, - ); - path = Cache; - sourceTree = ""; - }; 78E59B2B1C786CBF00C6BFE9 /* UITableView */ = { isa = PBXGroup; children = ( @@ -558,8 +526,6 @@ 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 */, 78CFEE521C5C45E500F50370 /* UITableView+CellRegistration.swift in Sources */, @@ -573,18 +539,15 @@ 786D78EC1D53C46E006B2CEA /* AlamofireManager+Extensions.swift in Sources */, 95B39A841D9C0C3E0057BD54 /* UIImage+Alpha.swift in Sources */, 95B39A801D9C09440057BD54 /* UIImage+Cropping.swift in Sources */, - 78E59B1B1C77470A00C6BFE9 /* ViewsGenerator.swift in Sources */, 78B0FC811C6B2CD500358B64 /* App.swift in Sources */, 78C36F771D80117D00E7EBEA /* UIImage+Transformations.swift in Sources */, 786D78EA1D53C43E006B2CEA /* ApiError.swift in Sources */, - 787A071A1D085750009EC97F /* CellsControllerProtocol.swift in Sources */, 95B39A861D9D51250057BD54 /* String+Localization.swift in Sources */, 78C36F7E1D801E3E00E7EBEA /* Double+Rounding.swift in Sources */, 78CFEE551C5C45E500F50370 /* NibNameProtocol.swift in Sources */, 78CFEE561C5C45E500F50370 /* ReuseIdentifierProtocol.swift in Sources */, 786D78E81D53C378006B2CEA /* AlamofireRequest+Extensions.swift in Sources */, 78C36F811D8021DD00E7EBEA /* UIColor+Hex.swift in Sources */, - 78E59B191C773EE600C6BFE9 /* ObjectsGenerator.swift in Sources */, 78CFEE5B1C5C45E500F50370 /* ViewModelProtocol.swift in Sources */, 78C36F7B1D8015ED00E7EBEA /* UIImage+Creation.swift in Sources */, 95B39A7A1D9BFD550057BD54 /* UIImage+Loading.swift in Sources */, diff --git a/LeadKit/LeadKit/Classes/Cache/ObjectsGenerator.swift b/LeadKit/LeadKit/Classes/Cache/ObjectsGenerator.swift deleted file mode 100644 index 8d2f17f4..00000000 --- a/LeadKit/LeadKit/Classes/Cache/ObjectsGenerator.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// ObjectsPool.swift -// LeadKit -// -// Created by Иван Смолин on 19/02/16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import Foundation - -/// class that generates objects on initialization phase and then return its when necessary -public class ObjectsGenerator { - private var objects = [T]() - - private let poolSize: UInt - - typealias ObjectConstructor = () -> T - - private let objectsContructor: ObjectConstructor - - private let serialQueue = dispatch_queue_create("ru.touchin.LeadKit.ObjectsGenerator<\(T.self)>", DISPATCH_QUEUE_SERIAL) - - /** - initializer function - - - parameter poolSize: number of objects to generate - - parameter contructor: objects constructor closure - */ - init(poolSize: UInt, objectsContructor contructor: ObjectConstructor) { - self.poolSize = poolSize - self.objectsContructor = contructor - - fillPool() - } - - private func fillPool() { - for _ in 0.. T { - dispatch_sync(serialQueue) { - if self.objects.count < 1 { - self.fillPool() - } - } - - return objects.popLast()! - } - -} diff --git a/LeadKit/LeadKit/Classes/Cache/ViewsGenerator.swift b/LeadKit/LeadKit/Classes/Cache/ViewsGenerator.swift deleted file mode 100644 index 5b7bef95..00000000 --- a/LeadKit/LeadKit/Classes/Cache/ViewsGenerator.swift +++ /dev/null @@ -1,23 +0,0 @@ -// -// TableViewCellsPool.swift -// LeadKit -// -// Created by Иван Смолин on 19/02/16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import Foundation - -/// class that generates views on initialization phase and then return its when necessary -public class ViewsGenerator: ObjectsGenerator { - /** - initializer function - - - parameter poolSize: number of cells to generate - - parameter nibName: view nib name - */ - init(poolSize: UInt, nibName: String) { - super.init(poolSize: poolSize, objectsContructor: { T.loadFromNib(named: nibName) }) - } - -} diff --git a/LeadKit/LeadKit/Controllers/TableViewController.swift b/LeadKit/LeadKit/Controllers/TableViewController.swift deleted file mode 100644 index 7fb3e0e8..00000000 --- a/LeadKit/LeadKit/Controllers/TableViewController.swift +++ /dev/null @@ -1,109 +0,0 @@ -// -// TableViewController.swift -// LeadKit -// -// Created by Ivan Smolin on 30/05/16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import UIKit - -public class TableViewController: UITableViewController, CellsControllerProtocol { - - private var cellsObjectsCreators: [String: ViewsGenerator] = [:] - - private let cellCreationType: CellCreationType - - private static let creationTypeKey = "CellCreationType" - - // MARK: - Initialization - - public init(style: UITableViewStyle, cellCreationType: CellCreationType = .OnTheFlight) { - self.cellCreationType = cellCreationType - super.init(style: style) - } - - public required init?(coder aDecoder: NSCoder) { - if let creationType = CellCreationType(rawValue: aDecoder.decodeIntegerForKey(TableViewController.creationTypeKey)) { - cellCreationType = creationType - super.init(coder: aDecoder) - } else { - return nil - } - } - - public override func encodeWithCoder(aCoder: NSCoder) { - super.encodeWithCoder(aCoder) - aCoder.encodeInteger(cellCreationType.rawValue, forKey: TableViewController.creationTypeKey) - } - - /** - 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 - } - - // MARK: - UITableViewDataSource - - public override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let cell: UITableViewCell - - let cellIdentifier = cellIdentifierForIndexPath(indexPath) - - switch cellCreationType { - case .OnTheFlight: - cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) - case .Preloaded: - guard let cellsGenerator = cellsObjectsCreators[cellIdentifier] else { - fatalError("You should register view generator for cell with identifier \"\(cellIdentifier)\"") - } - - cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) ?? cellsGenerator.get() - } - - configureCell(cell, atIndexPath: indexPath) - - return cell - } - - // 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 deleted file mode 100644 index a2d09dbf..00000000 --- a/LeadKit/LeadKit/Enums/CellCreationType.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// 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/Protocols/CellsControllerProtocol.swift b/LeadKit/LeadKit/Protocols/CellsControllerProtocol.swift deleted file mode 100644 index f24d0d3f..00000000 --- a/LeadKit/LeadKit/Protocols/CellsControllerProtocol.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// CellsControllerProtocol.swift -// LeadKit -// -// Created by Ivan Smolin on 08/06/16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import Foundation - -/** - * protocol which ensures that specific type can configure cell and return cell attributes for specific index path - */ -public protocol CellsControllerProtocol { - associatedtype CellType - - /** - method which returns cell identifier for given index path - - - parameter indexPath: NSIndexPath object - - - returns: cell identifier for specified index path - */ - func cellIdentifierForIndexPath(indexPath: NSIndexPath) -> String - - /** - method which configures given cell for given index path - - - parameter cell: cell to configure - - parameter atIndexPath: index path of given cell - - - returns: nothing - */ - func configureCell(cell: CellType, atIndexPath: NSIndexPath) - -} From 54bb8cd0d309d3bb3fa2138961441af3f3494774 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 6 Oct 2016 12:40:58 +0300 Subject: [PATCH 3/5] Swift 3 migration + huge refactoring --- Cartfile | 10 +- Cartfile.resolved | 10 +- LeadKit/LeadKit.xcodeproj/project.pbxproj | 205 +++++++++++------- .../xcshareddata/xcschemes/LeadKit.xcscheme | 2 +- LeadKit/LeadKit/Classes/Logging/App.swift | 29 +-- LeadKit/LeadKit/Classes/Logging/Log.swift | 16 +- .../Classes/Logging/LogFormatter.swift | 20 +- LeadKit/LeadKit/Enums/ApiError.swift | 8 +- .../AlamofireManager+Extensions.swift | 14 +- .../AlamofireRequest+Extensions.swift | 27 ++- .../CGContext/CGContext+Initializers.swift | 55 +++++ .../Extensions/CGImage/CGImage+Alpha.swift | 39 ++++ .../Extensions/CGImage/CGImage+Creation.swift | 64 ++++++ .../Extensions/CGImage/CGImage+Crop.swift | 35 +++ .../Extensions/CGImage/CGImage+Template.swift | 39 ++++ .../CGImage/CGImage+Transform.swift | 189 ++++++++++++++++ .../Extensions/CGImage/CGImage+Utils.swift | 29 +++ .../Extensions/Double/Double+Rounding.swift | 14 +- .../IndexPath+ImmutableIndexPath.swift} | 10 +- .../String/String+Localization.swift | 2 +- .../String/String+SizeCalculation.swift | 8 +- .../Extensions/UIColor/UIColor+Hex.swift | 8 +- .../Extensions/UIImage/UIImage+Alpha.swift | 123 ----------- .../UIImage/UIImage+CapInsetsUtils.swift | 71 ------ .../Extensions/UIImage/UIImage+Creation.swift | 57 ----- .../Extensions/UIImage/UIImage+Cropping.swift | 44 ---- .../UIImage/UIImage+Extensions.swift | 131 +++++++++++ .../UIImage/UIImage+Gradients.swift | 123 ----------- .../Extensions/UIImage/UIImage+Loading.swift | 72 ------ .../UIImage/UIImage+RenderTemplate.swift | 46 ---- .../Extensions/UIImage/UIImage+Resize.swift | 79 ------- .../Extensions/UIImage/UIImage+Text.swift | 45 ---- .../UIImage/UIImage+Transformations.swift | 154 ------------- .../UIImageView+LoadingImage.swift | 52 ----- ...Storyboard+InstantiateViewController.swift | 6 +- .../UITableView+CellRegistration.swift | 17 +- .../UITableView+DequeueCustomCell.swift | 7 +- .../UIView/UIView+DefaultNibName.swift | 10 +- .../UIView+DefaultReuseIdentifier.swift | 4 +- .../UIView/UIView+LoadFromNib.swift | 14 +- ...ntroller+DefaultStoryboardIdentifier.swift | 22 ++ LeadKit/LeadKit/Functions/Any+TypeName.swift | 19 ++ LeadKit/LeadKit/Info.plist | 2 +- .../LeadKit/Protocols/NibNameProtocol.swift | 2 +- .../Protocols/ReuseIdentifierProtocol.swift | 12 +- .../Protocols/StaticNibNameProtocol.swift | 4 +- .../StoryboardIdentifierProtocol.swift | 2 +- .../LeadKit/Protocols/ViewModelProtocol.swift | 2 +- .../Structures/Api/ApiRequestParameters.swift | 18 +- LeadKit/LeadKitTests/LeadKitTests.swift | 3 +- 50 files changed, 888 insertions(+), 1086 deletions(-) create mode 100644 LeadKit/LeadKit/Extensions/CGContext/CGContext+Initializers.swift create mode 100644 LeadKit/LeadKit/Extensions/CGImage/CGImage+Alpha.swift create mode 100644 LeadKit/LeadKit/Extensions/CGImage/CGImage+Creation.swift create mode 100644 LeadKit/LeadKit/Extensions/CGImage/CGImage+Crop.swift create mode 100644 LeadKit/LeadKit/Extensions/CGImage/CGImage+Template.swift create mode 100644 LeadKit/LeadKit/Extensions/CGImage/CGImage+Transform.swift create mode 100644 LeadKit/LeadKit/Extensions/CGImage/CGImage+Utils.swift rename LeadKit/LeadKit/Extensions/{NSIndexPath/NSIndexPath+ImmutableIndexPath.swift => IndexPath/IndexPath+ImmutableIndexPath.swift} (54%) delete mode 100644 LeadKit/LeadKit/Extensions/UIImage/UIImage+Alpha.swift delete mode 100644 LeadKit/LeadKit/Extensions/UIImage/UIImage+CapInsetsUtils.swift delete mode 100644 LeadKit/LeadKit/Extensions/UIImage/UIImage+Creation.swift delete mode 100644 LeadKit/LeadKit/Extensions/UIImage/UIImage+Cropping.swift create mode 100644 LeadKit/LeadKit/Extensions/UIImage/UIImage+Extensions.swift delete mode 100644 LeadKit/LeadKit/Extensions/UIImage/UIImage+Gradients.swift delete mode 100644 LeadKit/LeadKit/Extensions/UIImage/UIImage+Loading.swift delete mode 100644 LeadKit/LeadKit/Extensions/UIImage/UIImage+RenderTemplate.swift delete mode 100644 LeadKit/LeadKit/Extensions/UIImage/UIImage+Resize.swift delete mode 100644 LeadKit/LeadKit/Extensions/UIImage/UIImage+Text.swift delete mode 100644 LeadKit/LeadKit/Extensions/UIImage/UIImage+Transformations.swift delete mode 100644 LeadKit/LeadKit/Extensions/UIImageView/UIImageView+LoadingImage.swift create mode 100644 LeadKit/LeadKit/Extensions/UIViewController/UIViewController+DefaultStoryboardIdentifier.swift create mode 100644 LeadKit/LeadKit/Functions/Any+TypeName.swift diff --git a/Cartfile b/Cartfile index c0738da1..990789a4 100644 --- a/Cartfile +++ b/Cartfile @@ -1,5 +1,5 @@ -github "CocoaLumberjack/CocoaLumberjack" ~> 2.2 -github "ReactiveX/RxSwift" ~> 2.6 -github "lyft/mapper" ~> 3.0 -github "Alamofire/Alamofire" ~> 3.4 -github "RxSwiftCommunity/RxAlamofire" ~> 1.1 \ No newline at end of file +github "CocoaLumberjack/CocoaLumberjack" ~> 3.0.0 +github "ReactiveX/RxSwift" "3.0.0-beta.1" +github "lyft/mapper" "5.0.0-beta.2" +github "Alamofire/Alamofire" ~> 4.0.0 +github "RxSwiftCommunity/RxAlamofire" "3.0.0-beta.1" \ No newline at end of file diff --git a/Cartfile.resolved b/Cartfile.resolved index add1c1a2..b54d8082 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,5 +1,5 @@ -github "Alamofire/Alamofire" "3.4.1" -github "CocoaLumberjack/CocoaLumberjack" "2.3.0" -github "ReactiveX/RxSwift" "2.6.0" -github "lyft/mapper" "3.0.0" -github "RxSwiftCommunity/RxAlamofire" "1.2" +github "Alamofire/Alamofire" "4.0.1" +github "CocoaLumberjack/CocoaLumberjack" "3.0.0" +github "ReactiveX/RxSwift" "3.0.0-beta.1" +github "lyft/mapper" "5.0.0-beta.2" +github "RxSwiftCommunity/RxAlamofire" "3.0.0-beta.1" diff --git a/LeadKit/LeadKit.xcodeproj/project.pbxproj b/LeadKit/LeadKit.xcodeproj/project.pbxproj index 7137581a..b156d4ec 100644 --- a/LeadKit/LeadKit.xcodeproj/project.pbxproj +++ b/LeadKit/LeadKit.xcodeproj/project.pbxproj @@ -7,30 +7,34 @@ objects = { /* Begin PBXBuildFile section */ - 0A3BB96F1D5DCFE100B03CBD /* CocoaLumberjack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0A3BB96B1D5DCFE100B03CBD /* CocoaLumberjack.framework */; }; - 0A3BB9701D5DCFE100B03CBD /* Mapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0A3BB96C1D5DCFE100B03CBD /* Mapper.framework */; }; - 0A3BB9711D5DCFE100B03CBD /* RxAlamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0A3BB96D1D5DCFE100B03CBD /* RxAlamofire.framework */; }; - 0A3BB9721D5DCFE100B03CBD /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0A3BB96E1D5DCFE100B03CBD /* RxSwift.framework */; }; - 0A3BB9741D5DCFEC00B03CBD /* RxCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0A3BB9731D5DCFEC00B03CBD /* RxCocoa.framework */; }; 78011A641D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78011A631D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift */; }; 78011AB31D48B53600EA16A2 /* ApiRequestParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78011AB21D48B53600EA16A2 /* ApiRequestParameters.swift */; }; - 7824CA521CFEE6B700D7B132 /* UIImage+RenderTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7824CA511CFEE6B700D7B132 /* UIImage+RenderTemplate.swift */; }; + 780D23431DA412470084620D /* CGImage+Alpha.swift in Sources */ = {isa = PBXBuildFile; fileRef = 780D23421DA412470084620D /* CGImage+Alpha.swift */; }; + 780D23461DA416F80084620D /* CGContext+Initializers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 780D23451DA416F80084620D /* CGContext+Initializers.swift */; }; 7837F60F1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7837F60E1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift */; }; - 786A17A11CB8D71D007F9661 /* UIImage+CapInsetsUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 786A17A01CB8D71D007F9661 /* UIImage+CapInsetsUtils.swift */; }; 786D78E81D53C378006B2CEA /* AlamofireRequest+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 786D78E71D53C378006B2CEA /* AlamofireRequest+Extensions.swift */; }; 786D78EA1D53C43E006B2CEA /* ApiError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 786D78E91D53C43E006B2CEA /* ApiError.swift */; }; 786D78EC1D53C46E006B2CEA /* AlamofireManager+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 786D78EB1D53C46E006B2CEA /* AlamofireManager+Extensions.swift */; }; 787682FA1CAD40C300532AB3 /* StaticEstimatedViewHeightProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787682F91CAD40C200532AB3 /* StaticEstimatedViewHeightProtocol.swift */; }; - 787783631CA03CA0001CDC9B /* NSIndexPath+ImmutableIndexPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787783621CA03CA0001CDC9B /* NSIndexPath+ImmutableIndexPath.swift */; }; + 787783631CA03CA0001CDC9B /* IndexPath+ImmutableIndexPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787783621CA03CA0001CDC9B /* IndexPath+ImmutableIndexPath.swift */; }; 787783671CA04D4A001CDC9B /* String+SizeCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787783661CA04D4A001CDC9B /* String+SizeCalculation.swift */; }; 788EC15A1CF64528009CFB6B /* UIStoryboard+InstantiateViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 788EC1591CF64528009CFB6B /* UIStoryboard+InstantiateViewController.swift */; }; 78A74EA91C6B373700FE9724 /* UIView+DefaultNibName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78A74EA81C6B373700FE9724 /* UIView+DefaultNibName.swift */; }; + 78B036411DA4D7060021D5CC /* UIImage+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B036401DA4D7060021D5CC /* UIImage+Extensions.swift */; }; + 78B036431DA4FEC90021D5CC /* CGImage+Transform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B036421DA4FEC90021D5CC /* CGImage+Transform.swift */; }; + 78B036451DA561D00021D5CC /* CGImage+Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B036441DA561D00021D5CC /* CGImage+Utils.swift */; }; + 78B036471DA5624D0021D5CC /* CGImage+Creation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B036461DA5624D0021D5CC /* CGImage+Creation.swift */; }; + 78B036491DA562C30021D5CC /* CGImage+Template.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B036481DA562C30021D5CC /* CGImage+Template.swift */; }; + 78B0364B1DA61EDE0021D5CC /* CGImage+Crop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B0364A1DA61EDE0021D5CC /* CGImage+Crop.swift */; }; + 78B0365E1DA624C10021D5CC /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B036581DA624C10021D5CC /* Alamofire.framework */; }; + 78B0365F1DA624C10021D5CC /* CocoaLumberjack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B036591DA624C10021D5CC /* CocoaLumberjack.framework */; }; + 78B036601DA624C10021D5CC /* Mapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B0365A1DA624C10021D5CC /* Mapper.framework */; }; + 78B036611DA624C10021D5CC /* RxAlamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B0365B1DA624C10021D5CC /* RxAlamofire.framework */; }; + 78B036621DA624C10021D5CC /* RxCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B0365C1DA624C10021D5CC /* RxCocoa.framework */; }; + 78B036631DA624C10021D5CC /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B0365D1DA624C10021D5CC /* RxSwift.framework */; }; 78B0FC7D1C6B2BE200358B64 /* LogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B0FC7C1C6B2BE200358B64 /* LogFormatter.swift */; }; 78B0FC7F1C6B2C4D00358B64 /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B0FC7E1C6B2C4D00358B64 /* Log.swift */; }; 78B0FC811C6B2CD500358B64 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B0FC801C6B2CD500358B64 /* App.swift */; }; - 78C36F771D80117D00E7EBEA /* UIImage+Transformations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C36F761D80117D00E7EBEA /* UIImage+Transformations.swift */; }; - 78C36F791D8011FA00E7EBEA /* UIImage+Resize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C36F781D8011FA00E7EBEA /* UIImage+Resize.swift */; }; - 78C36F7B1D8015ED00E7EBEA /* UIImage+Creation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C36F7A1D8015ED00E7EBEA /* UIImage+Creation.swift */; }; 78C36F7E1D801E3E00E7EBEA /* Double+Rounding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C36F7D1D801E3E00E7EBEA /* Double+Rounding.swift */; }; 78C36F811D8021DD00E7EBEA /* UIColor+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C36F801D8021DD00E7EBEA /* UIColor+Hex.swift */; }; 78CFEE2E1C5C456B00F50370 /* LeadKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 78CFEE2D1C5C456B00F50370 /* LeadKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -46,12 +50,8 @@ 78CFEE591C5C45E500F50370 /* StoryboardIdentifierProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78CFEE4E1C5C45E500F50370 /* StoryboardIdentifierProtocol.swift */; }; 78CFEE5A1C5C45E500F50370 /* ViewHeightProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78CFEE4F1C5C45E500F50370 /* ViewHeightProtocol.swift */; }; 78CFEE5B1C5C45E500F50370 /* ViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78CFEE501C5C45E500F50370 /* ViewModelProtocol.swift */; }; - 95B39A781D9BFCC30057BD54 /* UIImageView+LoadingImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B39A771D9BFCC30057BD54 /* UIImageView+LoadingImage.swift */; }; - 95B39A7A1D9BFD550057BD54 /* UIImage+Loading.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B39A791D9BFD550057BD54 /* UIImage+Loading.swift */; }; - 95B39A7C1D9C05260057BD54 /* UIImage+Gradients.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B39A7B1D9C05260057BD54 /* UIImage+Gradients.swift */; }; - 95B39A7E1D9C069B0057BD54 /* UIImage+Text.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B39A7D1D9C069B0057BD54 /* UIImage+Text.swift */; }; - 95B39A801D9C09440057BD54 /* UIImage+Cropping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B39A7F1D9C09440057BD54 /* UIImage+Cropping.swift */; }; - 95B39A841D9C0C3E0057BD54 /* UIImage+Alpha.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B39A831D9C0C3E0057BD54 /* UIImage+Alpha.swift */; }; + 78D4B5461DA64D49005B0764 /* UIViewController+DefaultStoryboardIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78D4B5451DA64D49005B0764 /* UIViewController+DefaultStoryboardIdentifier.swift */; }; + 78D4B54A1DA64EAB005B0764 /* Any+TypeName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78D4B5491DA64EAB005B0764 /* Any+TypeName.swift */; }; 95B39A861D9D51250057BD54 /* String+Localization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B39A851D9D51250057BD54 /* String+Localization.swift */; }; /* End PBXBuildFile section */ @@ -66,30 +66,34 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 0A3BB96B1D5DCFE100B03CBD /* CocoaLumberjack.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = CocoaLumberjack.framework; sourceTree = ""; }; - 0A3BB96C1D5DCFE100B03CBD /* Mapper.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Mapper.framework; sourceTree = ""; }; - 0A3BB96D1D5DCFE100B03CBD /* RxAlamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = RxAlamofire.framework; sourceTree = ""; }; - 0A3BB96E1D5DCFE100B03CBD /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = RxSwift.framework; sourceTree = ""; }; - 0A3BB9731D5DCFEC00B03CBD /* RxCocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = RxCocoa.framework; sourceTree = ""; }; 78011A631D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+DefaultReuseIdentifier.swift"; sourceTree = ""; }; 78011AB21D48B53600EA16A2 /* ApiRequestParameters.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApiRequestParameters.swift; sourceTree = ""; }; - 7824CA511CFEE6B700D7B132 /* UIImage+RenderTemplate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+RenderTemplate.swift"; sourceTree = ""; }; + 780D23421DA412470084620D /* CGImage+Alpha.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGImage+Alpha.swift"; sourceTree = ""; }; + 780D23451DA416F80084620D /* CGContext+Initializers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGContext+Initializers.swift"; sourceTree = ""; }; 7837F60E1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EstimatedViewHeightProtocol.swift; sourceTree = ""; }; - 786A17A01CB8D71D007F9661 /* UIImage+CapInsetsUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+CapInsetsUtils.swift"; sourceTree = ""; }; 786D78E71D53C378006B2CEA /* AlamofireRequest+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AlamofireRequest+Extensions.swift"; sourceTree = ""; }; 786D78E91D53C43E006B2CEA /* ApiError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApiError.swift; sourceTree = ""; }; 786D78EB1D53C46E006B2CEA /* AlamofireManager+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AlamofireManager+Extensions.swift"; sourceTree = ""; }; 787682F91CAD40C200532AB3 /* StaticEstimatedViewHeightProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StaticEstimatedViewHeightProtocol.swift; sourceTree = ""; }; - 787783621CA03CA0001CDC9B /* NSIndexPath+ImmutableIndexPath.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSIndexPath+ImmutableIndexPath.swift"; sourceTree = ""; }; + 787783621CA03CA0001CDC9B /* IndexPath+ImmutableIndexPath.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "IndexPath+ImmutableIndexPath.swift"; sourceTree = ""; }; 787783661CA04D4A001CDC9B /* String+SizeCalculation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+SizeCalculation.swift"; sourceTree = ""; }; 788EC1591CF64528009CFB6B /* UIStoryboard+InstantiateViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIStoryboard+InstantiateViewController.swift"; sourceTree = ""; }; 78A74EA81C6B373700FE9724 /* UIView+DefaultNibName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIView+DefaultNibName.swift"; path = "LeadKit/Extensions/UIView/UIView+DefaultNibName.swift"; sourceTree = SOURCE_ROOT; }; + 78B036401DA4D7060021D5CC /* UIImage+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Extensions.swift"; sourceTree = ""; }; + 78B036421DA4FEC90021D5CC /* CGImage+Transform.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGImage+Transform.swift"; sourceTree = ""; }; + 78B036441DA561D00021D5CC /* CGImage+Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGImage+Utils.swift"; sourceTree = ""; }; + 78B036461DA5624D0021D5CC /* CGImage+Creation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGImage+Creation.swift"; sourceTree = ""; }; + 78B036481DA562C30021D5CC /* CGImage+Template.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGImage+Template.swift"; sourceTree = ""; }; + 78B0364A1DA61EDE0021D5CC /* CGImage+Crop.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGImage+Crop.swift"; sourceTree = ""; }; + 78B036581DA624C10021D5CC /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Alamofire.framework; path = ../../../Carthage/Build/iOS/Alamofire.framework; sourceTree = ""; }; + 78B036591DA624C10021D5CC /* CocoaLumberjack.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CocoaLumberjack.framework; path = ../../../Carthage/Build/iOS/CocoaLumberjack.framework; sourceTree = ""; }; + 78B0365A1DA624C10021D5CC /* Mapper.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Mapper.framework; path = ../../../Carthage/Build/iOS/Mapper.framework; sourceTree = ""; }; + 78B0365B1DA624C10021D5CC /* RxAlamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxAlamofire.framework; path = ../../../Carthage/Build/iOS/RxAlamofire.framework; sourceTree = ""; }; + 78B0365C1DA624C10021D5CC /* RxCocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxCocoa.framework; path = ../../../Carthage/Build/iOS/RxCocoa.framework; sourceTree = ""; }; + 78B0365D1DA624C10021D5CC /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = ../../../Carthage/Build/iOS/RxSwift.framework; sourceTree = ""; }; 78B0FC7C1C6B2BE200358B64 /* LogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogFormatter.swift; sourceTree = ""; }; 78B0FC7E1C6B2C4D00358B64 /* Log.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = ""; }; 78B0FC801C6B2CD500358B64 /* App.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = ""; }; - 78C36F761D80117D00E7EBEA /* UIImage+Transformations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Transformations.swift"; sourceTree = ""; }; - 78C36F781D8011FA00E7EBEA /* UIImage+Resize.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Resize.swift"; sourceTree = ""; }; - 78C36F7A1D8015ED00E7EBEA /* UIImage+Creation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Creation.swift"; sourceTree = ""; }; 78C36F7D1D801E3E00E7EBEA /* Double+Rounding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Double+Rounding.swift"; sourceTree = ""; }; 78C36F801D8021DD00E7EBEA /* UIColor+Hex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIColor+Hex.swift"; sourceTree = ""; }; 78CFEE2A1C5C456B00F50370 /* LeadKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LeadKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -108,12 +112,8 @@ 78CFEE4E1C5C45E500F50370 /* StoryboardIdentifierProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardIdentifierProtocol.swift; sourceTree = ""; }; 78CFEE4F1C5C45E500F50370 /* ViewHeightProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewHeightProtocol.swift; sourceTree = ""; }; 78CFEE501C5C45E500F50370 /* ViewModelProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewModelProtocol.swift; sourceTree = ""; }; - 95B39A771D9BFCC30057BD54 /* UIImageView+LoadingImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIImageView+LoadingImage.swift"; path = "UIImageView/UIImageView+LoadingImage.swift"; sourceTree = ""; }; - 95B39A791D9BFD550057BD54 /* UIImage+Loading.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Loading.swift"; sourceTree = ""; }; - 95B39A7B1D9C05260057BD54 /* UIImage+Gradients.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Gradients.swift"; sourceTree = ""; }; - 95B39A7D1D9C069B0057BD54 /* UIImage+Text.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Text.swift"; sourceTree = ""; }; - 95B39A7F1D9C09440057BD54 /* UIImage+Cropping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Cropping.swift"; sourceTree = ""; }; - 95B39A831D9C0C3E0057BD54 /* UIImage+Alpha.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Alpha.swift"; sourceTree = ""; }; + 78D4B5451DA64D49005B0764 /* UIViewController+DefaultStoryboardIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+DefaultStoryboardIdentifier.swift"; sourceTree = ""; }; + 78D4B5491DA64EAB005B0764 /* Any+TypeName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Any+TypeName.swift"; sourceTree = ""; }; 95B39A851D9D51250057BD54 /* String+Localization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Localization.swift"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -122,11 +122,12 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 0A3BB9721D5DCFE100B03CBD /* RxSwift.framework in Frameworks */, - 0A3BB96F1D5DCFE100B03CBD /* CocoaLumberjack.framework in Frameworks */, - 0A3BB9701D5DCFE100B03CBD /* Mapper.framework in Frameworks */, - 0A3BB9741D5DCFEC00B03CBD /* RxCocoa.framework in Frameworks */, - 0A3BB9711D5DCFE100B03CBD /* RxAlamofire.framework in Frameworks */, + 78B036601DA624C10021D5CC /* Mapper.framework in Frameworks */, + 78B0365F1DA624C10021D5CC /* CocoaLumberjack.framework in Frameworks */, + 78B036631DA624C10021D5CC /* RxSwift.framework in Frameworks */, + 78B0365E1DA624C10021D5CC /* Alamofire.framework in Frameworks */, + 78B036621DA624C10021D5CC /* RxCocoa.framework in Frameworks */, + 78B036611DA624C10021D5CC /* RxAlamofire.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -144,11 +145,12 @@ 0A3BB96A1D5DCFBD00B03CBD /* Frameworks */ = { isa = PBXGroup; children = ( - 0A3BB9731D5DCFEC00B03CBD /* RxCocoa.framework */, - 0A3BB96B1D5DCFE100B03CBD /* CocoaLumberjack.framework */, - 0A3BB96C1D5DCFE100B03CBD /* Mapper.framework */, - 0A3BB96D1D5DCFE100B03CBD /* RxAlamofire.framework */, - 0A3BB96E1D5DCFE100B03CBD /* RxSwift.framework */, + 78B036581DA624C10021D5CC /* Alamofire.framework */, + 78B036591DA624C10021D5CC /* CocoaLumberjack.framework */, + 78B0365A1DA624C10021D5CC /* Mapper.framework */, + 78B0365B1DA624C10021D5CC /* RxAlamofire.framework */, + 78B0365C1DA624C10021D5CC /* RxCocoa.framework */, + 78B0365D1DA624C10021D5CC /* RxSwift.framework */, ); path = Frameworks; sourceTree = ""; @@ -177,6 +179,27 @@ path = Api; sourceTree = ""; }; + 780D23411DA412330084620D /* CGImage */ = { + isa = PBXGroup; + children = ( + 780D23421DA412470084620D /* CGImage+Alpha.swift */, + 78B036421DA4FEC90021D5CC /* CGImage+Transform.swift */, + 78B036441DA561D00021D5CC /* CGImage+Utils.swift */, + 78B036461DA5624D0021D5CC /* CGImage+Creation.swift */, + 78B036481DA562C30021D5CC /* CGImage+Template.swift */, + 78B0364A1DA61EDE0021D5CC /* CGImage+Crop.swift */, + ); + path = CGImage; + sourceTree = ""; + }; + 780D23441DA416E80084620D /* CGContext */ = { + isa = PBXGroup; + children = ( + 780D23451DA416F80084620D /* CGContext+Initializers.swift */, + ); + path = CGContext; + sourceTree = ""; + }; 786D78E61D53C355006B2CEA /* Alamofire */ = { isa = PBXGroup; children = ( @@ -186,12 +209,12 @@ path = Alamofire; sourceTree = ""; }; - 787783611CA03C84001CDC9B /* NSIndexPath */ = { + 787783611CA03C84001CDC9B /* IndexPath */ = { isa = PBXGroup; children = ( - 787783621CA03CA0001CDC9B /* NSIndexPath+ImmutableIndexPath.swift */, + 787783621CA03CA0001CDC9B /* IndexPath+ImmutableIndexPath.swift */, ); - path = NSIndexPath; + path = IndexPath; sourceTree = ""; }; 787783651CA04D14001CDC9B /* String */ = { @@ -264,6 +287,7 @@ 78CFEE441C5C45E500F50370 /* Extensions */, 78011A651D47AF3000EA16A2 /* Enums */, 78CFEE491C5C45E500F50370 /* Protocols */, + 78D4B54B1DA650FC005B0764 /* Functions */, 78CFEE2D1C5C456B00F50370 /* LeadKit.h */, 78CFEE2F1C5C456B00F50370 /* Info.plist */, ); @@ -282,15 +306,17 @@ 78CFEE441C5C45E500F50370 /* Extensions */ = { isa = PBXGroup; children = ( - 95B39A761D9BFC930057BD54 /* UIImageView */, 78C36F7F1D8021D100E7EBEA /* UIColor */, 78C36F7C1D801E2F00E7EBEA /* Double */, 787783651CA04D14001CDC9B /* String */, - 787783611CA03C84001CDC9B /* NSIndexPath */, + 787783611CA03C84001CDC9B /* IndexPath */, 78E59B2C1C786CD500C6BFE9 /* UIView */, 78E59B2B1C786CBF00C6BFE9 /* UITableView */, C37210711ACDF1042F70C2EB /* UIImage */, + 780D23411DA412330084620D /* CGImage */, + 780D23441DA416E80084620D /* CGContext */, C372153938A7B7D327F55124 /* UIStoryboard */, + 78D4B5441DA64D31005B0764 /* UIViewController */, 786D78E61D53C355006B2CEA /* Alamofire */, ); path = Extensions; @@ -312,6 +338,22 @@ path = Protocols; sourceTree = ""; }; + 78D4B5441DA64D31005B0764 /* UIViewController */ = { + isa = PBXGroup; + children = ( + 78D4B5451DA64D49005B0764 /* UIViewController+DefaultStoryboardIdentifier.swift */, + ); + path = UIViewController; + sourceTree = ""; + }; + 78D4B54B1DA650FC005B0764 /* Functions */ = { + isa = PBXGroup; + children = ( + 78D4B5491DA64EAB005B0764 /* Any+TypeName.swift */, + ); + path = Functions; + sourceTree = ""; + }; 78E59B2B1C786CBF00C6BFE9 /* UITableView */ = { isa = PBXGroup; children = ( @@ -331,27 +373,10 @@ path = UIView; sourceTree = ""; }; - 95B39A761D9BFC930057BD54 /* UIImageView */ = { - isa = PBXGroup; - children = ( - 95B39A771D9BFCC30057BD54 /* UIImageView+LoadingImage.swift */, - ); - name = UIImageView; - sourceTree = ""; - }; C37210711ACDF1042F70C2EB /* UIImage */ = { isa = PBXGroup; children = ( - 786A17A01CB8D71D007F9661 /* UIImage+CapInsetsUtils.swift */, - 7824CA511CFEE6B700D7B132 /* UIImage+RenderTemplate.swift */, - 78C36F761D80117D00E7EBEA /* UIImage+Transformations.swift */, - 78C36F781D8011FA00E7EBEA /* UIImage+Resize.swift */, - 78C36F7A1D8015ED00E7EBEA /* UIImage+Creation.swift */, - 95B39A791D9BFD550057BD54 /* UIImage+Loading.swift */, - 95B39A7B1D9C05260057BD54 /* UIImage+Gradients.swift */, - 95B39A7D1D9C069B0057BD54 /* UIImage+Text.swift */, - 95B39A7F1D9C09440057BD54 /* UIImage+Cropping.swift */, - 95B39A831D9C0C3E0057BD54 /* UIImage+Alpha.swift */, + 78B036401DA4D7060021D5CC /* UIImage+Extensions.swift */, ); path = UIImage; sourceTree = ""; @@ -424,14 +449,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Touch Instinct"; TargetAttributes = { 78CFEE291C5C456B00F50370 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; 78CFEE331C5C456B00F50370 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; }; }; @@ -528,41 +555,40 @@ files = ( 7837F60F1CBCF5C0000D74C1 /* EstimatedViewHeightProtocol.swift in Sources */, 78CFEE541C5C45E500F50370 /* UIView+LoadFromNib.swift in Sources */, + 78D4B5461DA64D49005B0764 /* UIViewController+DefaultStoryboardIdentifier.swift in Sources */, 78CFEE521C5C45E500F50370 /* UITableView+CellRegistration.swift in Sources */, 78B0FC7F1C6B2C4D00358B64 /* Log.swift in Sources */, + 78D4B54A1DA64EAB005B0764 /* Any+TypeName.swift in Sources */, 78CFEE571C5C45E500F50370 /* StaticNibNameProtocol.swift in Sources */, 788EC15A1CF64528009CFB6B /* UIStoryboard+InstantiateViewController.swift in Sources */, 787783671CA04D4A001CDC9B /* String+SizeCalculation.swift in Sources */, + 78B036431DA4FEC90021D5CC /* CGImage+Transform.swift in Sources */, 78011A641D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift in Sources */, 78CFEE531C5C45E500F50370 /* UITableView+DequeueCustomCell.swift in Sources */, - 95B39A781D9BFCC30057BD54 /* UIImageView+LoadingImage.swift in Sources */, 786D78EC1D53C46E006B2CEA /* AlamofireManager+Extensions.swift in Sources */, - 95B39A841D9C0C3E0057BD54 /* UIImage+Alpha.swift in Sources */, - 95B39A801D9C09440057BD54 /* UIImage+Cropping.swift in Sources */, 78B0FC811C6B2CD500358B64 /* App.swift in Sources */, - 78C36F771D80117D00E7EBEA /* UIImage+Transformations.swift in Sources */, + 78B036491DA562C30021D5CC /* CGImage+Template.swift in Sources */, 786D78EA1D53C43E006B2CEA /* ApiError.swift in Sources */, + 780D23461DA416F80084620D /* CGContext+Initializers.swift in Sources */, 95B39A861D9D51250057BD54 /* String+Localization.swift in Sources */, 78C36F7E1D801E3E00E7EBEA /* Double+Rounding.swift in Sources */, 78CFEE551C5C45E500F50370 /* NibNameProtocol.swift in Sources */, 78CFEE561C5C45E500F50370 /* ReuseIdentifierProtocol.swift in Sources */, + 78B036411DA4D7060021D5CC /* UIImage+Extensions.swift in Sources */, 786D78E81D53C378006B2CEA /* AlamofireRequest+Extensions.swift in Sources */, 78C36F811D8021DD00E7EBEA /* UIColor+Hex.swift in Sources */, 78CFEE5B1C5C45E500F50370 /* ViewModelProtocol.swift in Sources */, - 78C36F7B1D8015ED00E7EBEA /* UIImage+Creation.swift in Sources */, - 95B39A7A1D9BFD550057BD54 /* UIImage+Loading.swift in Sources */, - 7824CA521CFEE6B700D7B132 /* UIImage+RenderTemplate.swift in Sources */, + 780D23431DA412470084620D /* CGImage+Alpha.swift in Sources */, 78CFEE5A1C5C45E500F50370 /* ViewHeightProtocol.swift in Sources */, 787682FA1CAD40C300532AB3 /* StaticEstimatedViewHeightProtocol.swift in Sources */, - 95B39A7E1D9C069B0057BD54 /* UIImage+Text.swift in Sources */, 78A74EA91C6B373700FE9724 /* UIView+DefaultNibName.swift in Sources */, - 786A17A11CB8D71D007F9661 /* UIImage+CapInsetsUtils.swift in Sources */, - 78C36F791D8011FA00E7EBEA /* UIImage+Resize.swift in Sources */, 78CFEE581C5C45E500F50370 /* StaticViewHeightProtocol.swift in Sources */, - 787783631CA03CA0001CDC9B /* NSIndexPath+ImmutableIndexPath.swift in Sources */, + 787783631CA03CA0001CDC9B /* IndexPath+ImmutableIndexPath.swift in Sources */, + 78B036471DA5624D0021D5CC /* CGImage+Creation.swift in Sources */, + 78B0364B1DA61EDE0021D5CC /* CGImage+Crop.swift in Sources */, + 78B036451DA561D00021D5CC /* CGImage+Utils.swift in Sources */, 78CFEE591C5C45E500F50370 /* StoryboardIdentifierProtocol.swift in Sources */, 78011AB31D48B53600EA16A2 /* ApiRequestParameters.swift in Sources */, - 95B39A7C1D9C05260057BD54 /* UIImage+Gradients.swift in Sources */, 78B0FC7D1C6B2BE200358B64 /* LogFormatter.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -599,8 +625,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -623,7 +651,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.2; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -647,8 +675,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -665,9 +695,10 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.2; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -678,6 +709,7 @@ 78CFEE3F1C5C456B00F50370 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -690,17 +722,19 @@ ); INFOPLIST_FILE = LeadKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = ru.touchin.LeadKit; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Debug; }; 78CFEE401C5C456B00F50370 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -713,11 +747,12 @@ ); INFOPLIST_FILE = LeadKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = ru.touchin.LeadKit; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -728,6 +763,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = ru.touchin.LeadKitTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -738,6 +774,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = ru.touchin.LeadKitTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/LeadKit/LeadKit.xcodeproj/xcshareddata/xcschemes/LeadKit.xcscheme b/LeadKit/LeadKit.xcodeproj/xcshareddata/xcschemes/LeadKit.xcscheme index b7823617..8a426cb3 100644 --- a/LeadKit/LeadKit.xcodeproj/xcshareddata/xcschemes/LeadKit.xcscheme +++ b/LeadKit/LeadKit.xcodeproj/xcshareddata/xcschemes/LeadKit.xcscheme @@ -1,6 +1,6 @@ String { + open static var version: String { return App.shortVersion + "." + App.bundleVersion } @@ -29,14 +30,16 @@ public class App { Return device identifier - returns: UUIDString */ - public static func stringIdentifierForVendor() -> String { - var returnValue = NSUserDefaults.standardUserDefaults().stringForKey(App.stringVendorIdentifierKey) - if returnValue == nil { - returnValue = NSUUID().UUIDString - NSUserDefaults.standardUserDefaults().setObject(returnValue, forKey: App.stringVendorIdentifierKey) - NSUserDefaults.standardUserDefaults().synchronize() + open static var stringIdentifierForVendor: String { + if let vendorIdentifier = UserDefaults.standard.string(forKey: App.stringVendorIdentifierKey) { + return vendorIdentifier } - return returnValue! + + let vendorIdentifier = UUID().uuidString + UserDefaults.standard.set(vendorIdentifier, forKey: App.stringVendorIdentifierKey) + UserDefaults.standard.synchronize() + + return vendorIdentifier } } diff --git a/LeadKit/LeadKit/Classes/Logging/Log.swift b/LeadKit/LeadKit/Classes/Logging/Log.swift index 7fe07a17..752d8905 100644 --- a/LeadKit/LeadKit/Classes/Logging/Log.swift +++ b/LeadKit/LeadKit/Classes/Logging/Log.swift @@ -9,24 +9,24 @@ import Foundation import CocoaLumberjack -public class Log { +open class Log { /// Logger for CocoaLumberJack - public let fileLogger = DDFileLogger() + open let fileLogger = DDFileLogger() init() { - DDLog.addLogger(fileLogger) + DDLog.add(fileLogger) - DDLog.addLogger(DDASLLogger.sharedInstance()) - DDLog.addLogger(DDTTYLogger.sharedInstance()) + DDLog.add(DDASLLogger.sharedInstance()) + DDLog.add(DDTTYLogger.sharedInstance()) DDASLLogger.sharedInstance().logFormatter = LogFormatter() DDTTYLogger.sharedInstance().logFormatter = LogFormatter() let assertionHandler = NSAssertionHandler() - NSThread.currentThread().threadDictionary.setValue(assertionHandler, forKey: NSAssertionHandlerKey) + Thread.current.threadDictionary.setValue(assertionHandler, forKey: NSAssertionHandlerKey) } /** @@ -34,10 +34,10 @@ public class Log { - returns: Return value looks like "AppName 1.0.1 session started on version 9.2 (build 13c75)" */ - public static func startMessage() -> String { + open static var startMessage: String { let startMessage = App.bundleName + " " + App.shortVersion + "." + App.bundleVersion + " session started on " - + NSProcessInfo.processInfo().operatingSystemVersionString.lowercaseString + + ProcessInfo.processInfo.operatingSystemVersionString.lowercased() return startMessage } diff --git a/LeadKit/LeadKit/Classes/Logging/LogFormatter.swift b/LeadKit/LeadKit/Classes/Logging/LogFormatter.swift index 172b6e40..86a232fb 100644 --- a/LeadKit/LeadKit/Classes/Logging/LogFormatter.swift +++ b/LeadKit/LeadKit/Classes/Logging/LogFormatter.swift @@ -11,33 +11,33 @@ import CocoaLumberjack import CocoaLumberjack.DDDispatchQueueLogFormatter class LogFormatter: DDDispatchQueueLogFormatter { - let dateFormatter: NSDateFormatter + let dateFormatter: DateFormatter override init() { - dateFormatter = NSDateFormatter() - dateFormatter.formatterBehavior = .Behavior10_4 + dateFormatter = DateFormatter() + dateFormatter.formatterBehavior = .behavior10_4 dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss:SSS" super.init() } - override func formatLogMessage(logMessage: DDLogMessage!) -> String { - var level: String! + override func format(message logMessage: DDLogMessage) -> String { + let level: String switch logMessage.flag { - case DDLogFlag.Error: + case DDLogFlag.error: level = "ERR" - case DDLogFlag.Warning: + case DDLogFlag.warning: level = "WRN" - case DDLogFlag.Info: + case DDLogFlag.info: level = "INF" - case DDLogFlag.Debug: + case DDLogFlag.debug: level = "DBG" default: level = "VRB" } - let dateAndTime = dateFormatter.stringFromDate(logMessage.timestamp) + let dateAndTime = dateFormatter.string(from: logMessage.timestamp) return "\(level) \(dateAndTime) [\(logMessage.fileName):\(logMessage.line)]: \(logMessage.message)" } diff --git a/LeadKit/LeadKit/Enums/ApiError.swift b/LeadKit/LeadKit/Enums/ApiError.swift index 7d897105..db23929f 100644 --- a/LeadKit/LeadKit/Enums/ApiError.swift +++ b/LeadKit/LeadKit/Enums/ApiError.swift @@ -13,10 +13,10 @@ - JSONSerialization: JSON serialization error - ObjectSerialization: object mapping error */ -public enum RequestError: ErrorType { +public enum RequestError: Error { - case Network(error: NSError) - case JSONSerialization(error: NSError) - case Mapping(reason: String) + case network(error: Error) + case jsonSerialization(error: Error) + case mapping(reason: String) } diff --git a/LeadKit/LeadKit/Extensions/Alamofire/AlamofireManager+Extensions.swift b/LeadKit/LeadKit/Extensions/Alamofire/AlamofireManager+Extensions.swift index ad8f110d..5e16ebe3 100644 --- a/LeadKit/LeadKit/Extensions/Alamofire/AlamofireManager+Extensions.swift +++ b/LeadKit/LeadKit/Extensions/Alamofire/AlamofireManager+Extensions.swift @@ -10,7 +10,7 @@ import Alamofire import RxSwift import RxAlamofire -public extension Alamofire.Manager { +public extension Alamofire.SessionManager { /** method which executes request with given api parameters @@ -19,12 +19,12 @@ public extension Alamofire.Manager { - returns: Observable with request */ - func apiRequest(apiParameters: ApiRequestParameters) -> Observable { - return rx_request(apiParameters.method, - apiParameters.url, - parameters: apiParameters.parameters, - encoding: apiParameters.encoding, - headers: apiParameters.headers) + func apiRequest(requestParameters: ApiRequestParameters) -> Observable { + return RxAlamofire.request(requestParameters.method, + requestParameters.url, + parameters: requestParameters.parameters, + encoding: requestParameters.encoding, + headers: requestParameters.headers) } } diff --git a/LeadKit/LeadKit/Extensions/Alamofire/AlamofireRequest+Extensions.swift b/LeadKit/LeadKit/Extensions/Alamofire/AlamofireRequest+Extensions.swift index af933a9f..23ba9ee5 100644 --- a/LeadKit/LeadKit/Extensions/Alamofire/AlamofireRequest+Extensions.swift +++ b/LeadKit/LeadKit/Extensions/Alamofire/AlamofireRequest+Extensions.swift @@ -10,36 +10,39 @@ import Alamofire import RxSwift import Mapper import RxAlamofire +import struct RxCocoa.Reactive -public extension Alamofire.Request { +public extension Reactive where Base: DataRequest { /** method which serialize response into target object - returns: Observable with HTTP URL Response and target object */ - func apiResponse() -> Observable<(NSHTTPURLResponse, T)> { - let mapperSerializer = ResponseSerializer { request, response, data, error in + func apiResponse() -> Observable<(HTTPURLResponse, T)> { + let mapperSerializer = DataResponseSerializer { request, response, data, error in if let err = error { - return .Failure(.Network(error: err)) + return .failure(RequestError.network(error: err)) } - let jsonResponseSerializer = Request.JSONResponseSerializer(options: .AllowFragments) + let jsonResponseSerializer = DataRequest.jsonResponseSerializer() let result = jsonResponseSerializer.serializeResponse(request, response, data, error) switch result { - case .Success(let value): - if let responseObject = value as? NSDictionary, mappedObject = T.from(responseObject) { - return .Success(mappedObject) + case .success(let value): + if let responseObject = value as? NSDictionary, let mappedObject = T.from(responseObject) { + return .success(mappedObject) } else { - return .Failure(.Mapping(reason: "JSON could not be mapped into response object. JSON: \(value)")) + let failureReason = "JSON could not be mapped into response object. JSON: \(value)" + + return .failure(RequestError.mapping(reason: failureReason)) } - case .Failure(let error): - return .Failure(.JSONSerialization(error: error)) + case .failure(let error): + return .failure(RequestError.jsonSerialization(error: error)) } } - return rx_responseResult(responseSerializer: mapperSerializer) + return responseResult(responseSerializer: mapperSerializer) } } diff --git a/LeadKit/LeadKit/Extensions/CGContext/CGContext+Initializers.swift b/LeadKit/LeadKit/Extensions/CGContext/CGContext+Initializers.swift new file mode 100644 index 00000000..b24efa21 --- /dev/null +++ b/LeadKit/LeadKit/Extensions/CGContext/CGContext+Initializers.swift @@ -0,0 +1,55 @@ +// +// CGContext+Initializers.swift +// LeadKit +// +// Created by Ivan Smolin on 04/10/16. +// Copyright © 2016 Touch Instinct. All rights reserved. +// + +import CoreGraphics + +public extension CGContext { + + /** + method which creates an instance of CGContext with parameters taken from a given image + + - parameter forCGImage: CGImage instance from which the parameters will be taken + - parameter fallbackColorSpace: fallback color space if image doesn't have it + */ + public static func create(forCGImage cgImage: CGImage, + fallbackColorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB()) -> CGContext? { + + return create(width: cgImage.width, + height: cgImage.height, + bitmapInfo: cgImage.bitmapInfo, + colorSpace: cgImage.colorSpace ?? fallbackColorSpace, + bitsPerComponent: cgImage.bitsPerComponent) + } + + /** + method which creates an instance of CGContext + + - parameter width: The width, in pixels, of the required bitmap. + - parameter height: The height, in pixels, of the required bitmap. + - parameter bitmapInfo: Constants that specify whether the bitmap should contain an alpha channel, + the alpha channel’s relative location in a pixel, + and information about whether the pixel components are floating-point or integer values. + - parameter colorSpace: The color space to use for the bitmap context. + - parameter bitsPerComponent: The number of bits to use for each component of a pixel in memory. + */ + public static func create(width: Int, + height: Int, + bitmapInfo: CGBitmapInfo = alphaBitmapInfo, + colorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB(), + bitsPerComponent: Int = 8) -> CGContext? { + + return CGContext(data: nil, + width: width, + height: height, + bitsPerComponent: bitsPerComponent, + bytesPerRow: 0, + space: colorSpace, + bitmapInfo: bitmapInfo.rawValue) + } + +} diff --git a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Alpha.swift b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Alpha.swift new file mode 100644 index 00000000..329b05dd --- /dev/null +++ b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Alpha.swift @@ -0,0 +1,39 @@ +// +// CGImage+Alpha.swift +// LeadKit +// +// Created by Ivan Smolin on 04/10/16. +// Copyright © 2016 Touch Instinct. All rights reserved. +// + +import CoreGraphics + +public extension CGImage { + + /** + - returns: true if the image has an alpha layer. + */ + public var hasAlpha: Bool { + switch alphaInfo { + case .first, .last, .premultipliedFirst, .premultipliedLast: + return true + default: + return false + } + } + + /** + - returns: a copy of the given image, adding an alpha channel if it doesn't already have one. + */ + public func applyAlpha() -> CGImage? { + guard !hasAlpha else { + return self + } + + let ctx = CGContext.create(width: width, height: height, bitmapInfo: alphaBitmapInfo) + ctx?.draw(self, in: bounds) + + return ctx?.makeImage() + } + +} diff --git a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Creation.swift b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Creation.swift new file mode 100644 index 00000000..ed153870 --- /dev/null +++ b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Creation.swift @@ -0,0 +1,64 @@ +// +// CGImage+Creation.swift +// LeadKit +// +// Created by Ivan Smolin on 05/10/16. +// Copyright © 2016 Touch Instinct. All rights reserved. +// + +import CoreGraphics + +public extension CGImage { + + /** + method which creates new CGImage instance filled by given color + + - parameter color: color to fill + - parameter width: width of new image + - parameter height: height of new image + - parameter opaque: a flag indicating whether the bitmap is opaque (default: False) + + - returns: new instanse of UIImage with given size and color + */ + public static func create(color: CGColor, + width: Int, + height: Int, + opaque: Bool = false) -> CGImage? { + + let context = CGContext.create(width: width, + height: height, + bitmapInfo: opaque ? opaqueBitmapInfo : alphaBitmapInfo) + + guard let ctx = context else { + return nil + } + + ctx.setFillColor(color) + ctx.fill(CGRect(origin: CGPoint.zero, size: CGSize(width: width, height: height))) + + return ctx.makeImage() + } + + /** + creates an image from a UIView. + + - parameter fromView: The source view. + + - returns A new image + */ + public static func create(fromView view: UIView) -> CGImage? { + let size = view.bounds.size + + let ctxWidth = Int(ceil(size.width)) + let ctxHeight = Int(ceil(size.height)) + + guard let ctx = CGContext.create(width: ctxWidth, height: ctxHeight) else { + return nil + } + + view.layer.render(in: ctx) + + return ctx.makeImage() + } + +} diff --git a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Crop.swift b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Crop.swift new file mode 100644 index 00000000..600e6040 --- /dev/null +++ b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Crop.swift @@ -0,0 +1,35 @@ +// +// CGImage+Crop.swift +// LeadKit +// +// Created by Ivan Smolin on 06/10/16. +// Copyright © 2016 Touch Instinct. All rights reserved. +// + +import CoreGraphics + +public extension CGImage { + + /** + crop image to square from center + + - returns: cropped image + */ + public func cropFromCenterToSquare() -> CGImage? { + let shortest = min(width, height) + + let widthCropSize = width > shortest ? (width - shortest) : 0 + let heightCropSize = height > shortest ? (height - shortest) : 0 + + let left = widthCropSize / 2 + let top = heightCropSize / 2 + + let cropRect = CGRect(x: left, + y: top, + width: width - widthCropSize, + height: height - heightCropSize) + + return cropping(to: cropRect) + } + +} diff --git a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Template.swift b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Template.swift new file mode 100644 index 00000000..96436b7c --- /dev/null +++ b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Template.swift @@ -0,0 +1,39 @@ +// +// CGImage+Template.swift +// LeadKit +// +// Created by Ivan Smolin on 05/10/16. +// Copyright © 2016 Touch Instinct. All rights reserved. +// + +import CoreGraphics + +public extension CGImage { + + /** + method which render current template CGImage into new image using given color + + - parameter color: color which used to fill template image + + - returns: new CGImage rendered with given color or nil if something goes wrong + */ + public func renderTemplate(withColor color: CGColor) -> CGImage? { + guard let ctx = CGContext.create(forCGImage: self) ?? CGContext.create(width: width, height: height) else { + return nil + } + + let imageRect = bounds + + ctx.setFillColor(color) + + ctx.translateBy(x: 0, y: CGFloat(height)) + ctx.scaleBy(x: 1.0, y: -1.0) + ctx.clip(to: imageRect, mask: self) + ctx.fill(imageRect) + + ctx.setBlendMode(.multiply) + + return ctx.makeImage() + } + +} diff --git a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Transform.swift b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Transform.swift new file mode 100644 index 00000000..5ef478fa --- /dev/null +++ b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Transform.swift @@ -0,0 +1,189 @@ +// +// CGImage+Transform.swift +// LeadKit +// +// Created by Ivan Smolin on 05/10/16. +// Copyright © 2016 Touch Instinct. All rights reserved. +// + +import CoreGraphics + +public extension CGImage { + + /** + creates a new image with rounded corners. + + - parameter withRadius: The corner radius. + + - returns: A new image + */ + public func round(withRadius radius: CGFloat) -> CGImage? { + guard let ctx = CGContext.create(forCGImage: self) ?? CGContext.create(width: width, height: height) else { + return nil + } + + ctx.addPath(UIBezierPath(roundedRect: bounds, cornerRadius: radius).cgPath) + ctx.clip() + ctx.draw(self, in: bounds) + + return ctx.makeImage() + } + + /** + creates a new image with a border. + + - parameter width: The size of the border. + - parameter color: The color of the border. + - parameter radius: The corner radius. + - parameter extendSize: Extend result image size and don't overlap source image by border. + + - returns: A new image + */ + public func applyBorder(width border: CGFloat, + color: CGColor, + radius: CGFloat = 0, + extendSize: Bool = false) -> CGImage? { + + let offset = extendSize ? border : 0 + + let newWidth = CGFloat(width) + offset * 2 + let newHeight = CGFloat(height) + offset * 2 + + let ctxWidth = Int(ceil(newWidth)) + let ctxHeight = Int(ceil(newHeight)) + + let ctxRect: CGRect = CGRect(origin: CGPoint.zero, size: CGSize(width: newWidth, height: newHeight)) + + let context = CGContext.create(width: ctxWidth, + height: ctxHeight, + bitmapInfo: bitmapInfo, + colorSpace: colorSpace ?? CGColorSpaceCreateDeviceRGB(), + bitsPerComponent: bitsPerComponent) + + guard let ctx = context ?? CGContext.create(width: width, height: height) else { + return nil + } + + ctx.draw(self, in: CGRect(x: offset, y: offset, width: CGFloat(width), height: CGFloat(height))) + + ctx.setStrokeColor(color) + + let widthDiff = CGFloat(ctxWidth) - newWidth // difference between context width and real width + let heightDiff = CGFloat(ctxWidth) - newWidth // difference between context height and real height + + let inset = ctxRect.insetBy(dx: border / 2 + widthDiff, dy: border / 2 + heightDiff) + + if radius != 0 { + ctx.setLineWidth(border) + ctx.addPath(UIBezierPath(roundedRect: inset, cornerRadius: radius).cgPath) + ctx.strokePath() + } else { + ctx.stroke(inset, width: border) + } + + return ctx.makeImage() + } + + /** + creates a resized copy of an image. + + - parameter newSize: the new size of the image. + - parameter contentMode: the way to handle the content in the new size. + + - returns: a new image + */ + public func resize(newSize: CGSize, contentMode: ImageContentMode = .scaleToFill) -> CGImage? { + let ctxWidth = Int(ceil(newSize.width)) + let ctxHeight = Int(ceil(newSize.height)) + + let context = CGContext.create(width: ctxWidth, + height: ctxHeight, + bitmapInfo: bitmapInfo, + colorSpace: colorSpace ?? CGColorSpaceCreateDeviceRGB(), + bitsPerComponent: bitsPerComponent) + + guard let ctx = context ?? CGContext.create(width: ctxWidth, height: ctxHeight) else { + return nil + } + + let horizontalRatio = newSize.width / CGFloat(width) + let verticalRatio = newSize.height / CGFloat(height) + + let ratio: CGFloat + + switch contentMode { + case .scaleToFill: + ratio = 1 + case .scaleAspectFill: + ratio = max(horizontalRatio, verticalRatio) + case .scaleAspectFit: + ratio = min(horizontalRatio, verticalRatio) + } + + let newImageWidth = contentMode == .scaleToFill ? newSize.width : CGFloat(width) * ratio + let newImageHeight = contentMode == .scaleToFill ? newSize.height : CGFloat(height) * ratio + + let originX: CGFloat + let originY: CGFloat + + if newImageWidth > newSize.width { + originX = (newSize.width - newImageWidth) / 2 + } else if newImageWidth < newSize.width { + originX = newSize.width / 2 - newImageWidth / 2 + } else { + originX = 0 + } + + if newImageHeight > newSize.height { + originY = (newSize.height - newImageHeight) / 2 + } else if newImageHeight < newSize.height { + originY = newSize.height / 2 - newImageHeight / 2 + } else { + originY = 0 + } + + let rect = CGRect(origin: CGPoint(x: originX, y: originY), + size: CGSize(width: newImageWidth, height: newImageHeight)) + + ctx.interpolationQuality = .high + ctx.draw(self, in: rect) + + return ctx.makeImage() + } + + /** + returns a copy of the image with border of the given size added around its edges. + + - parameter padding: The padding amount. + + - returns: A new image. + */ + public func applyPadding(_ padding: CGFloat) -> CGImage? { + let ctxWidth = Int(ceil(CGFloat(width) + padding * 2)) + let ctxHeight = Int(ceil(CGFloat(height) + padding * 2)) + + let context = CGContext.create(width: ctxWidth, + height: ctxHeight, + bitmapInfo: bitmapInfo, + colorSpace: colorSpace ?? CGColorSpaceCreateDeviceRGB(), + bitsPerComponent: bitsPerComponent) + + guard let ctx = context ?? CGContext.create(width: ctxWidth, height: ctxHeight) else { + return nil + } + + // Draw the image in the center of the context, leaving a gap around the edges + let imageLocation = CGRect(x: padding, + y: padding, + width: CGFloat(width), + height: CGFloat(height)) + + ctx.addRect(imageLocation) + ctx.clip() + + ctx.draw(self, in: imageLocation) + + return ctx.makeImage() + } + +} diff --git a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Utils.swift b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Utils.swift new file mode 100644 index 00000000..a821cd1c --- /dev/null +++ b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Utils.swift @@ -0,0 +1,29 @@ +// +// CGImage+Utils.swift +// LeadKit +// +// Created by Ivan Smolin on 05/10/16. +// Copyright © 2016 Touch Instinct. All rights reserved. +// + +import CoreGraphics + +// The bitmapInfo value are hard-coded to prevent an "unsupported parameter combination" error + +public let alphaBitmapInfo = CGBitmapInfo(rawValue: CGBitmapInfo().rawValue | CGImageAlphaInfo.premultipliedFirst.rawValue) +public let opaqueBitmapInfo = CGBitmapInfo(rawValue: CGBitmapInfo().rawValue | CGImageAlphaInfo.none.rawValue) + +public enum ImageContentMode { + case scaleToFill, scaleAspectFit, scaleAspectFill +} + +public extension CGImage { + + /** + - returns: bounds of image. + */ + var bounds: CGRect { + return CGRect(origin: CGPoint.zero, size: CGSize(width: width, height: height)) + } + +} diff --git a/LeadKit/LeadKit/Extensions/Double/Double+Rounding.swift b/LeadKit/LeadKit/Extensions/Double/Double+Rounding.swift index df520977..97bb45c3 100644 --- a/LeadKit/LeadKit/Extensions/Double/Double+Rounding.swift +++ b/LeadKit/LeadKit/Extensions/Double/Double+Rounding.swift @@ -17,8 +17,8 @@ public extension Double { - Down: From 167.567 you will get 167.5 */ public enum RoundingType { - case Normal - case Down + case normal + case down } /** @@ -30,14 +30,14 @@ public extension Double { - returns: rounded value */ public func roundValue(withPersicion persicion: UInt, - roundType: RoundingType = .Normal) -> Double { + roundType: RoundingType = .normal) -> Double { let divider = pow(10.0, Double(persicion)) switch roundType { - case .Normal: - return round(self * divider) / divider - case .Down: - return Double(Int(self * divider)) / divider + case .normal: + return (self * divider).rounded(.up) / divider + case .down: + return (self * divider).rounded(.down) / divider } } diff --git a/LeadKit/LeadKit/Extensions/NSIndexPath/NSIndexPath+ImmutableIndexPath.swift b/LeadKit/LeadKit/Extensions/IndexPath/IndexPath+ImmutableIndexPath.swift similarity index 54% rename from LeadKit/LeadKit/Extensions/NSIndexPath/NSIndexPath+ImmutableIndexPath.swift rename to LeadKit/LeadKit/Extensions/IndexPath/IndexPath+ImmutableIndexPath.swift index a1d34a31..d47b7ddf 100644 --- a/LeadKit/LeadKit/Extensions/NSIndexPath/NSIndexPath+ImmutableIndexPath.swift +++ b/LeadKit/LeadKit/Extensions/IndexPath/IndexPath+ImmutableIndexPath.swift @@ -1,5 +1,5 @@ // -// NSIndexPath+ImmutableIndexPath.swift +// IndexPath+ImmutableIndexPath.swift // LeadKit // // Created by Иван Смолин on 21/03/16. @@ -10,14 +10,14 @@ import Foundation // http://stackoverflow.com/a/21686163 -extension NSIndexPath { +extension IndexPath { /// return immutable copy if class is not NSIndexPath or return self - var immutableIndexPath: NSIndexPath { - if Mirror(reflecting: self).subjectType == NSIndexPath.self { // check for UIMutableIndexPath + var immutableIndexPath: IndexPath { + if Mirror(reflecting: self).subjectType == IndexPath.self { // check for UIMutableIndexPath return self } - return NSIndexPath(forItem: item, inSection: section) + return IndexPath(item: item, section: section) } } diff --git a/LeadKit/LeadKit/Extensions/String/String+Localization.swift b/LeadKit/LeadKit/Extensions/String/String+Localization.swift index 98c45e4d..b3c78c0f 100644 --- a/LeadKit/LeadKit/Extensions/String/String+Localization.swift +++ b/LeadKit/LeadKit/Extensions/String/String+Localization.swift @@ -6,7 +6,7 @@ // Copyright © 2016 Touch Instinct. All rights reserved. // -import UIKit +import Foundation public extension String { diff --git a/LeadKit/LeadKit/Extensions/String/String+SizeCalculation.swift b/LeadKit/LeadKit/Extensions/String/String+SizeCalculation.swift index f4e89b4b..c56ff1b4 100644 --- a/LeadKit/LeadKit/Extensions/String/String+SizeCalculation.swift +++ b/LeadKit/LeadKit/Extensions/String/String+SizeCalculation.swift @@ -52,11 +52,11 @@ public extension String { - returns: string size calculation result */ public func size(withAttributes attributes: [String: AnyObject]?, - maxWidth: CGFloat = CGFloat.max, - maxHeight: CGFloat = CGFloat.max) -> StringSizeCalculationResult { + maxWidth: CGFloat = CGFloat.greatestFiniteMagnitude, + maxHeight: CGFloat = CGFloat.greatestFiniteMagnitude) -> StringSizeCalculationResult { - let size = self.boundingRectWithSize(CGSize(width: maxWidth, height: maxHeight), - options: [.UsesLineFragmentOrigin, .UsesFontLeading], + let size = self.boundingRect(with: CGSize(width: maxWidth, height: maxHeight), + options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: attributes, context: nil).size diff --git a/LeadKit/LeadKit/Extensions/UIColor/UIColor+Hex.swift b/LeadKit/LeadKit/Extensions/UIColor/UIColor+Hex.swift index 1ef9f821..4a1d731b 100644 --- a/LeadKit/LeadKit/Extensions/UIColor/UIColor+Hex.swift +++ b/LeadKit/LeadKit/Extensions/UIColor/UIColor+Hex.swift @@ -75,7 +75,13 @@ public extension UIColor { - parameter alpha: alpha component used if not given in hexString */ public convenience init?(hexString: String, alpha: CGFloat = 1) { - let hexStr = hexString.hasPrefix("#") ? hexString.substringFromIndex(hexString.startIndex.advancedBy(1)) : hexString + let hexStr: String + + if hexString.hasPrefix("#") { + hexStr = hexString.substring(from: hexString.characters.index(hexString.startIndex, offsetBy: 1)) + } else { + hexStr = hexString + } let charactersCount = hexStr.characters.count diff --git a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Alpha.swift b/LeadKit/LeadKit/Extensions/UIImage/UIImage+Alpha.swift deleted file mode 100644 index 8f19bff8..00000000 --- a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Alpha.swift +++ /dev/null @@ -1,123 +0,0 @@ -// -// UIImage+Alpha.swift -// LeadKit -// -// Created by Николай Ашанин on 28.09.16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import UIKit - -public extension UIImage { - - /** - - returns: true if the image has an alpha layer. - */ - public func hasAlpha() -> Bool { - let alpha = CGImageGetAlphaInfo(CGImage) - switch alpha { - case .First, .Last, .PremultipliedFirst, .PremultipliedLast: - return true - default: - return false - } - } - - /** - - returns: a copy of the given image, adding an alpha channel if it doesn't already have one. - */ - public func applyAlpha() -> UIImage? { - guard !hasAlpha() else { - return self - } - - let imageRef = CGImage - let width = CGImageGetWidth(imageRef) - let height = CGImageGetHeight(imageRef) - let colorSpace = CGImageGetColorSpace(imageRef) - - // The bitsPerComponent and bitmapInfo values are hard-coded to prevent an "unsupported parameter combination" error - let bitmapInfo = CGBitmapInfo(rawValue: CGBitmapInfo.ByteOrderDefault.rawValue | - CGImageAlphaInfo.PremultipliedFirst.rawValue) - let offscreenContext = CGBitmapContextCreate(nil, width, height, 8, 0, colorSpace, bitmapInfo.rawValue) - - // Draw the image into the context and retrieve the new image, which will now have an alpha layer - CGContextDrawImage(offscreenContext, - CGRect(x: 0, y: 0, width: width, height: height), - imageRef) - guard let cgImage = CGBitmapContextCreateImage(offscreenContext) else { - return nil - } - let imageWithAlpha = UIImage(CGImage: cgImage) - return imageWithAlpha - } - - /** - returns a copy of the image with a transparent border of the given size added around its edges. - i.e. For rotating an image without getting jagged edges. - - - parameter padding: The padding amount. - - - returns: A new image. - */ - public func applyPadding(padding: CGFloat) -> UIImage? { - // If the image does not have an alpha layer, add one - guard let image = applyAlpha() else { - return nil - } - let rect = CGRect(x: 0, y: 0, width: size.width + padding * 2, height: size.height + padding * 2) - - // Build a context that's the same dimensions as the new size - let colorSpace = CGImageGetColorSpace(CGImage) - let bitmapInfo = CGImageGetBitmapInfo(CGImage) - let bitsPerComponent = CGImageGetBitsPerComponent(CGImage) - let context = CGBitmapContextCreate(nil, - Int(rect.size.width), - Int(rect.size.height), - bitsPerComponent, 0, colorSpace, - bitmapInfo.rawValue) - - // Draw the image in the center of the context, leaving a gap around the edges - let imageLocation = CGRect(x: padding, y: padding, width: image.size.width, height: image.size.height) - CGContextDrawImage(context, imageLocation, CGImage) - - // Create a mask to make the border transparent, and combine it with the image - let imageWithPadding = imageRefWithPadding(padding, size: rect.size) - guard let cgImage = CGImageCreateWithMask(CGBitmapContextCreateImage(context), imageWithPadding) else { - return nil - } - let transparentImage = UIImage(CGImage: cgImage) - return transparentImage - } - - /** - creates a mask that makes the outer edges transparent and everything else opaque. - The size must include the entire mask (opaque part + transparent border). - - - parameter padding: The padding amount. - - parameter size: The size of the image. - - - returns: A Core Graphics Image Ref - */ - private func imageRefWithPadding(padding: CGFloat, - size: CGSize) -> CGImageRef? { - // Build a context that's the same dimensions as the new size - let colorSpace = CGColorSpaceCreateDeviceGray() - let bitmapInfo = CGBitmapInfo(rawValue: CGBitmapInfo.ByteOrderDefault.rawValue | CGImageAlphaInfo.None.rawValue) - let context = CGBitmapContextCreate(nil, Int(size.width), Int(size.height), 8, 0, colorSpace, bitmapInfo.rawValue) - // Start with a mask that's entirely transparent - CGContextSetFillColorWithColor(context, UIColor.blackColor().CGColor) - CGContextFillRect(context, CGRect(x: 0, y: 0, width: size.width, height: size.height)) - // Make the inner part (within the border) opaque - CGContextSetFillColorWithColor(context, UIColor.whiteColor().CGColor) - let fillRect = CGRect(x: padding, - y: padding, - width: size.width - padding * 2, - height: size.height - padding * 2) - CGContextFillRect(context, fillRect) - // Get an image of the context - let maskImageRef = CGBitmapContextCreateImage(context) - return maskImageRef - } - -} diff --git a/LeadKit/LeadKit/Extensions/UIImage/UIImage+CapInsetsUtils.swift b/LeadKit/LeadKit/Extensions/UIImage/UIImage+CapInsetsUtils.swift deleted file mode 100644 index 6883fb60..00000000 --- a/LeadKit/LeadKit/Extensions/UIImage/UIImage+CapInsetsUtils.swift +++ /dev/null @@ -1,71 +0,0 @@ -// -// UIImage+CapInsetsUtils.swift -// LeadKit -// -// Created by Иван Смолин on 09/04/16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import UIKit - -public extension UIImage { - - /** - this method tries to find requested image with specific parameters in cache, and if doesn't exists - create it - - - parameter name: name of the image used in UIImage(named:) - - parameter size: size of rendered image - - parameter capInsets: cap insets for image - - parameter cache: cache to search - - - returns: cached or newly created image or nil if no such image find with specified name - */ - public static func fetchOrCreateImageWithName(name: String, - size: CGSize, - capInsets: UIEdgeInsets, - cache: NSCache) -> UIImage? { - let cacheKey = "\(name)-\(NSStringFromUIEdgeInsets(capInsets))-\(NSStringFromCGSize(size))" - - if let cachedImage = cache.objectForKey(cacheKey) as? UIImage { - return cachedImage - } - - if let renderedImage = UIImage(named: name)?.resizableImageWithCapInsets(capInsets).renderWithSize(size) { - cache.setObject(renderedImage, forKey: cacheKey) - - return renderedImage - } - - return nil - } - - /** - this method tries to find requested image with specific parameters in cache, and if doesn't exists - create it - - - parameter name: name of the image used in UIImage(named:) - - parameter size: size of rendered image - - parameter assetsInsetsForScales: mapping of screen scale to UIEdgeInsets which defined in XCAssets - - parameter cache: cache to search - - - returns: cached or newly created image or nil if no such image find with specified name - */ - public static func fetchOrCreateImageWithName(name: String, - size: CGSize, - assetsInsetsForScales: [CGFloat: UIEdgeInsets], - cache: NSCache) -> UIImage? { - let scale = UIScreen.mainScreen().scale - - if let assetsInsetsForScale = assetsInsetsForScales[scale] { - let capInsetsForScale = UIEdgeInsets(top: assetsInsetsForScale.top / scale, - left: assetsInsetsForScale.left / scale, - bottom: assetsInsetsForScale.bottom / scale, - right: assetsInsetsForScale.right / scale) - - - return fetchOrCreateImageWithName(name, size: size, capInsets: capInsetsForScale, cache: cache) - } - - return nil - } - -} diff --git a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Creation.swift b/LeadKit/LeadKit/Extensions/UIImage/UIImage+Creation.swift deleted file mode 100644 index 9417d85a..00000000 --- a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Creation.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// UIImage+Creation.swift -// LeadKit -// -// Created by Ivan Smolin on 07/09/16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import UIKit - -public extension UIImage { - - /** - method which creates new UIImage instance filled by given color - - - parameter color: color to fill - - parameter size: size of new image - - parameter opaque: a flag indicating whether the bitmap is opaque (default: False) - - parameter scale: screen scale (default: 0 (pick a device scale)) - - - returns: new instanse of UIImage with given size and color - */ - public static func imageWith(color: UIColor, size: CGSize, opaque: Bool = false, scale: CGFloat = 0) -> UIImage { - UIGraphicsBeginImageContextWithOptions(size, opaque, scale) - - defer { UIGraphicsEndImageContext() } - - let context = UIGraphicsGetCurrentContext() - - CGContextSetFillColorWithColor(context, color.CGColor) - CGContextFillRect(context, CGRect(origin: CGPoint.zero, size: size)) - - return UIGraphicsGetImageFromCurrentImageContext() - } - - /** - creates an image from a UIView. - - - parameter fromView: The source view. - - - returns A new image - */ - public convenience init?(fromView view: UIView) { - UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, 0) - - guard let context = UIGraphicsGetCurrentContext() else { - return nil - } - view.layer.renderInContext(context) - guard let cgImage = UIGraphicsGetImageFromCurrentImageContext().CGImage else { - return nil - } - self.init(CGImage: cgImage) - UIGraphicsEndImageContext() - } - -} diff --git a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Cropping.swift b/LeadKit/LeadKit/Extensions/UIImage/UIImage+Cropping.swift deleted file mode 100644 index e0d5a149..00000000 --- a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Cropping.swift +++ /dev/null @@ -1,44 +0,0 @@ -// -// UIImage+Cropping.swift -// LeadKit -// -// Created by Николай Ашанин on 28.09.16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import UIKit - -public extension UIImage { - - /** - creates a cropped copy of an image. - - - parameter bounds: The bounds of the rectangle inside the image. - - - returns: A new image - */ - public func crop(bounds: CGRect) -> UIImage? { - guard let cgImage = CGImageCreateWithImageInRect(CGImage, bounds) else { - return nil - } - return UIImage(CGImage: cgImage, - scale: 0.0, - orientation: imageOrientation) - } - - /** - crop image to square - - - returns: cropped image - */ - public func cropToSquare() -> UIImage? { - let scaledSize = CGSize(width: size.width * scale, height: size.height * scale) - let shortest = min(scaledSize.width, scaledSize.height) - let left: CGFloat = scaledSize.width > shortest ? (scaledSize.width-shortest)/2 : 0 - let top: CGFloat = scaledSize.height > shortest ? (scaledSize.height-shortest)/2 : 0 - let rect = CGRect(x: 0, y: 0, width: scaledSize.width, height: scaledSize.height) - let insetRect = CGRectInset(rect, left, top) - return crop(insetRect) - } - -} diff --git a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Extensions.swift b/LeadKit/LeadKit/Extensions/UIImage/UIImage+Extensions.swift new file mode 100644 index 00000000..f278fb85 --- /dev/null +++ b/LeadKit/LeadKit/Extensions/UIImage/UIImage+Extensions.swift @@ -0,0 +1,131 @@ +// +// UIImage+Extensions.swift +// LeadKit +// +// Created by Ivan Smolin on 05/10/16. +// Copyright © 2016 Touch Instinct. All rights reserved. +// + +import UIKit + +public extension UIImage { + + public convenience init?(color: UIColor, size: CGSize) { + let cgImage = CGImage.create(color: color.cgColor, + width: Int(ceil(size.width)), + height: Int(ceil(size.height))) + + guard let image = cgImage else { + return nil + } + + self.init(cgImage: image) + } + + public convenience init?(fromView view: UIView) { + guard let cgImage = CGImage.create(fromView: view) else { + return nil + } + + self.init(cgImage: cgImage) + } + + public func renderTemplate(withColor color: UIColor) -> UIImage? { + return cgImage?.renderTemplate(withColor: color.cgColor)?.uiImage + } + + /** + creates a new image with rounded corners and border. + + - parameter cornerRadius: The corner radius. + - parameter border: The size of the border. + - parameter color: The color of the border. + - parameter extendSize: Extend result image size and don't overlap source image by border. + + - returns: A new image + */ + public func roundCorners(cornerRadius: CGFloat, + borderWidth: CGFloat, + color: UIColor, + extendSize: Bool = false) -> UIImage? { + + let rounded = cgImage?.round(withRadius: cornerRadius) + + return rounded?.applyBorder(width: borderWidth, + color: color.cgColor, + radius: cornerRadius, + extendSize: extendSize)?.uiImage + } + + /** + creates a new circle image. + + - returns: A new image + */ + public func roundCornersToCircle() -> UIImage? { + return cgImage?.round(withRadius: CGFloat(min(size.width, size.height) / 2))?.uiImage + } + + /** + creates a new circle image with a border. + + - parameter border: CGFloat The size of the border. + - parameter color: UIColor The color of the border. + - parameter extendSize: Extend result image size and don't overlap source image by border. + + - returns: UIImage? + */ + public func roundCornersToCircle(borderWidth: CGFloat, + borderColor: UIColor, + extendSize: Bool = false) -> UIImage? { + + let radius = CGFloat(min(size.width, size.height) / 2) + let rounded = cgImage?.round(withRadius: radius) + + return rounded?.applyBorder(width: borderWidth, + color: borderColor.cgColor, + radius: radius, + extendSize: extendSize)?.uiImage + } + + /** + creates a resized copy of an image. + + - parameter newSize: the new size of the image. + - parameter contentMode: the way to handle the content in the new size. + + - returns: a new image + */ + public func resize(newSize: CGSize, contentMode: ImageContentMode = .scaleToFill) -> UIImage? { + return cgImage?.resize(newSize: newSize, contentMode: contentMode)?.uiImage + } + + /** + creates a cropped copy of an image. + + - parameter to: The bounds of the rectangle inside the image. + + - returns: A new image + */ + public func crop(to bounds: CGRect) -> UIImage? { + return cgImage?.cropping(to: bounds)?.uiImage + } + + /** + crop image to square from center + + - returns: cropped image + */ + public func cropFromCenterToSquare() -> UIImage? { + return cgImage?.cropFromCenterToSquare()?.uiImage + } + +} + +public extension CGImage { + + public var uiImage: UIImage { + return UIImage(cgImage: self) + } + +} diff --git a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Gradients.swift b/LeadKit/LeadKit/Extensions/UIImage/UIImage+Gradients.swift deleted file mode 100644 index 8aae3327..00000000 --- a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Gradients.swift +++ /dev/null @@ -1,123 +0,0 @@ -// -// UIImage+Gradients.swift -// LeadKit -// -// Created by Николай Ашанин on 28.09.16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import UIKit - -public extension UIImage { - - /** - creates a gradient color image. - - - parameter gradientColors: An array of colors to use for the gradient. - - parameter size: Image size (defaults: 10x10) - */ - public convenience init?(gradientColors: [UIColor], - size: CGSize = CGSize(width: 10, height: 10)) { - UIGraphicsBeginImageContextWithOptions(size, false, 0) - let context = UIGraphicsGetCurrentContext() - let colorSpace = CGColorSpaceCreateDeviceRGB() - let colors = gradientColors.map { $0.CGColor } - let gradient = CGGradientCreateWithColors(colorSpace, colors, nil) - CGContextDrawLinearGradient(context, - gradient, - CGPoint(x: 0, y: 0), - CGPoint(x: 0, y: size.height), - CGGradientDrawingOptions(rawValue: 0)) - guard let cgImage = UIGraphicsGetImageFromCurrentImageContext().CGImage else { - return nil - } - self.init(CGImage: cgImage) - UIGraphicsEndImageContext() - } - - /** - applies gradient color overlay to an image. - - - parameter gradientColors: An array of colors to use for the gradient. - - parameter blendMode: The blending type to use. - - - returns: A new image - */ - public func applyGradientColors(gradientColors: [UIColor], - blendMode: CGBlendMode = .Normal) -> UIImage { - UIGraphicsBeginImageContextWithOptions(size, false, scale) - let context = UIGraphicsGetCurrentContext() - CGContextTranslateCTM(context, 0, size.height) - CGContextScaleCTM(context, 1.0, -1.0) - CGContextSetBlendMode(context, blendMode) - let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) - CGContextDrawImage(context, rect, CGImage) - // Create gradient - let colorSpace = CGColorSpaceCreateDeviceRGB() - let colors = gradientColors.map { $0.CGColor } - let gradient = CGGradientCreateWithColors(colorSpace, colors, nil) - // Apply gradient - CGContextClipToMask(context, rect, CGImage) - CGContextDrawLinearGradient(context, - gradient, - CGPoint(x: 0, y: 0), - CGPoint(x: 0, y: size.height), - CGGradientDrawingOptions(rawValue: 0)) - let image = UIGraphicsGetImageFromCurrentImageContext() - UIGraphicsEndImageContext() - return image - } - - /** - creates a radial gradient. - - - parameter startColor: The start color - - parameter endColor: The end color - - parameter radialGradientCenter: The gradient center (default:0.5,0.5). - - parameter radius: Radius size (default: 0.5) - - parameter size: Image size (default: 100x100) - */ - public convenience init?(startColor: UIColor, - endColor: UIColor, - radialGradientCenter: CGPoint = CGPoint(x: 0.5, y: 0.5), - radius: CGFloat = 0.5, - size: CGSize = CGSize(width: 100, height: 100)) { - UIGraphicsBeginImageContextWithOptions(size, true, 0) - - let numLocations: Int = 2 - let locations: [CGFloat] = [0.0, 1.0] - - let startComponents = CGColorGetComponents(startColor.CGColor) - let endComponents = CGColorGetComponents(endColor.CGColor) - - let components: [CGFloat] = [startComponents[0], - startComponents[1], - startComponents[2], - startComponents[3], - endComponents[0], - endComponents[1], - endComponents[2], - endComponents[3]] as [CGFloat] - - let colorSpace = CGColorSpaceCreateDeviceRGB() - let gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, numLocations) - - // Normalize the 0-1 ranged inputs to the width of the image - let aCenter = CGPoint(x: radialGradientCenter.x * size.width, - y: radialGradientCenter.y * size.height) - let aRadius = (min(size.width, size.height)) * (radius) - - // Draw it - CGContextDrawRadialGradient(UIGraphicsGetCurrentContext(), - gradient, aCenter, 0, - aCenter, aRadius, - CGGradientDrawingOptions.DrawsAfterEndLocation) - guard let cgImage = UIGraphicsGetImageFromCurrentImageContext().CGImage else { - return nil - } - self.init(CGImage: cgImage) - // Clean up - UIGraphicsEndImageContext() - } - -} diff --git a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Loading.swift b/LeadKit/LeadKit/Extensions/UIImage/UIImage+Loading.swift deleted file mode 100644 index fe65d1ee..00000000 --- a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Loading.swift +++ /dev/null @@ -1,72 +0,0 @@ -// -// UIImage+Loading.swift -// LeadKit -// -// Created by Николай Ашанин on 28.09.16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import UIKit -import QuartzCore -import CoreGraphics -import Accelerate - -public enum UIImageContentMode { - case ScaleToFill, ScaleAspectFit, ScaleAspectFill -} - -public extension UIImage { - - /** - a singleton shared NSURL cache used for images from URL - */ - private static let sharedCache = NSCache() - - // MARK: Image From URL - - /** - creates a new image from a URL with optional caching. - if using cache, the cached image is returned. - otherwise, a place holder is used until the image from web is returned by the fetchComplete. - - - parameter url: The image URL. - - parameter placeholder: The placeholder image. - - parameter cacheImage: Weather or not we should cache the NSURL response (default: true) - - parameter fetchComplete: Returns the image from the web the first time is fetched. - - - returns: A new image - */ - public class func imageFromURL(url: String, - placeholder: UIImage, - cacheImage: Bool = true, - fetchComplete: (image: UIImage?) -> ()) -> UIImage? { - // From Cache - if cacheImage { - if let image = UIImage.sharedCache.objectForKey(url) as? UIImage { - fetchComplete(image: nil) - return image - } - } - // Fetch Image - let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration()) - if let nsURL = NSURL(string: url) { - session.dataTaskWithURL(nsURL, completionHandler: { (data, response, error) -> Void in - if error != nil { - dispatch_async(dispatch_get_main_queue()) { - fetchComplete(image: nil) - } - } else if let data = data, image = UIImage(data: data) { - if cacheImage { - UIImage.sharedCache.setObject(image, forKey: url) - } - dispatch_async(dispatch_get_main_queue()) { - fetchComplete(image: image) - } - } - session.finishTasksAndInvalidate() - }).resume() - } - return placeholder - } - -} diff --git a/LeadKit/LeadKit/Extensions/UIImage/UIImage+RenderTemplate.swift b/LeadKit/LeadKit/Extensions/UIImage/UIImage+RenderTemplate.swift deleted file mode 100644 index cd5a85c5..00000000 --- a/LeadKit/LeadKit/Extensions/UIImage/UIImage+RenderTemplate.swift +++ /dev/null @@ -1,46 +0,0 @@ -// -// UIImage+RenderTemplate.swift -// LeadKit -// -// Created by Ivan Smolin on 01/06/16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import UIKit - -public extension UIImage { - - /** - method which render current template UIImage into new image using given color - - - parameter color: color which used to fill template image - - parameter opaque: a flag indicating whether the bitmap is opaque (default: False) - - - returns: new UIImage rendered with given color - */ - public func renderTemplateWithColor(color: UIColor, opaque: Bool = false) -> UIImage { - UIGraphicsBeginImageContextWithOptions(size, opaque, scale) - - defer { UIGraphicsEndImageContext() } - - let ctx = UIGraphicsGetCurrentContext() - - let imageRect = CGRect(origin: CGPoint.zero, size: size) - - var r: CGFloat = 0, g: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0 - - color.getRed(&r, green: &g, blue: &b, alpha: &a) - CGContextSetRGBFillColor(ctx, r, g, b, a) - - CGContextTranslateCTM(ctx, 0, size.height) - CGContextScaleCTM(ctx, 1.0, -1.0) - CGContextClipToMask(ctx, imageRect, CGImage) - CGContextFillRect(ctx, imageRect) - - CGContextSetBlendMode(ctx, .Multiply) - CGContextDrawImage(ctx, imageRect, CGImage) - - return UIGraphicsGetImageFromCurrentImageContext() - } - -} diff --git a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Resize.swift b/LeadKit/LeadKit/Extensions/UIImage/UIImage+Resize.swift deleted file mode 100644 index f2efac47..00000000 --- a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Resize.swift +++ /dev/null @@ -1,79 +0,0 @@ -// -// UIImage+Resize.swift -// LeadKit -// -// Created by Ivan Smolin on 07/09/16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import UIKit - -public extension UIImage { - - /** - method which render current UIImage for specific size and return new UIImage - - - parameter size: size of new image - - parameter opaque: a flag indicating whether the bitmap is opaque (default: False) - - - returns: new instance of UIImage rendered with given size - */ - public func renderWithSize(size: CGSize, opaque: Bool = false) -> UIImage { - UIGraphicsBeginImageContextWithOptions(size, opaque, scale) - - defer { UIGraphicsEndImageContext() } - - drawInRect(CGRect(origin: CGPoint.zero, size: size)) - - return UIGraphicsGetImageFromCurrentImageContext() - } - - /** - creates a resized copy of an image. - - - parameter size: the new size of the image. - - parameter contentMode: the way to handle the content in the new size. - - - returns: a new image - */ - public func resize(size: CGSize, - contentMode: UIImageContentMode = .ScaleToFill) -> UIImage? { - let horizontalRatio = size.width / size.width - let verticalRatio = size.height / size.height - var ratio: CGFloat = 1 - - switch contentMode { - case .ScaleToFill: - ratio = 1 - case .ScaleAspectFill: - ratio = max(horizontalRatio, verticalRatio) - case .ScaleAspectFit: - ratio = min(horizontalRatio, verticalRatio) - } - - let rect = CGRect(x: 0, y: 0, width: size.width * ratio, height: size.height * ratio) - - let colorSpace = CGColorSpaceCreateDeviceRGB() - let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue) - let context = CGBitmapContextCreate(nil, - Int(rect.size.width), - Int(rect.size.height), 8, 0, colorSpace, - bitmapInfo.rawValue) - let transform = CGAffineTransformIdentity - CGContextConcatCTM(context, transform) - // Set the quality level to use when rescaling - guard let interpolationQuality = CGInterpolationQuality(rawValue: 3) else { - return nil - } - CGContextSetInterpolationQuality(context, interpolationQuality) - CGContextDrawImage(context, rect, CGImage) - - guard let newContext = context, cgImage = CGBitmapContextCreateImage(newContext) else { - return nil - } - return UIImage(CGImage: cgImage, - scale: scale, - orientation: imageOrientation) - } - -} diff --git a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Text.swift b/LeadKit/LeadKit/Extensions/UIImage/UIImage+Text.swift deleted file mode 100644 index 79dfe2b2..00000000 --- a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Text.swift +++ /dev/null @@ -1,45 +0,0 @@ -// -// UIImage+Text.swift -// LeadKit -// -// Created by Николай Ашанин on 28.09.16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import UIKit - -public extension UIImage { - - /** - creates a text label image. - - - parameter text: The text to use in the label. - - parameter font: The font (default: System font of size 18) - - parameter color: The text color (default: White) - - parameter backgroundColor: The background color (default:Gray). - - parameter size: Image size (default: 10x10) - - parameter offset: Center offset (default: 0x0) - */ - public convenience init?(text: String, - font: UIFont = UIFont.systemFontOfSize(18), - color: UIColor = UIColor.whiteColor(), - backgroundColor: UIColor = UIColor.grayColor(), - size: CGSize = CGSize(width: 10, height: 10), - offset: CGPoint = CGPoint(x: 0, y: 0)) { - let label = UILabel(frame: CGRect(x: 0, y: 0, width: size.width, height: size.height)) - label.font = font - label.text = text - label.textColor = color - label.textAlignment = .Center - label.backgroundColor = backgroundColor - let image = UIImage(fromView: label) - UIGraphicsBeginImageContextWithOptions(size, false, 0) - image?.drawInRect(CGRect(x: 0, y: 0, width: size.width, height: size.height)) - guard let cgImage = UIGraphicsGetImageFromCurrentImageContext().CGImage else { - return nil - } - self.init(CGImage: cgImage) - UIGraphicsEndImageContext() - } - -} diff --git a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Transformations.swift b/LeadKit/LeadKit/Extensions/UIImage/UIImage+Transformations.swift deleted file mode 100644 index 25435101..00000000 --- a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Transformations.swift +++ /dev/null @@ -1,154 +0,0 @@ -// -// UIImage+Transformations.swift -// LeadKit -// -// Created by Ivan Smolin on 07/09/16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import UIKit - -public extension UIImage { - - /** - method which creates new UIImage from current with rounded corners - - - parameter radius: corners radius - - parameter opaque: a flag indicating whether the bitmap is opaque (default: False) - - - returns: new UIImage instance rendered with given radius - */ - public func roundedImage(withRadius radius: CGFloat, opaque: Bool = false) -> UIImage { - UIGraphicsBeginImageContextWithOptions(size, opaque, scale) - - defer { UIGraphicsEndImageContext() } - - let imageRect = CGRect(origin: CGPoint.zero, size: size) - - UIBezierPath(roundedRect: imageRect, cornerRadius: radius).addClip() - - drawInRect(imageRect) - - return UIGraphicsGetImageFromCurrentImageContext() - } - - /** - creates a new image with rounded corners. - - - parameter cornerRadius: The corner radius. - - - returns: A new image - */ - public func roundCorners(cornerRadius: CGFloat) -> UIImage? { - guard let imageWithAlpha = applyAlpha() else { - return nil - } - UIGraphicsBeginImageContextWithOptions(size, false, 0) - let width = CGImageGetWidth(imageWithAlpha.CGImage) - let height = CGImageGetHeight(imageWithAlpha.CGImage) - let bits = CGImageGetBitsPerComponent(imageWithAlpha.CGImage) - let colorSpace = CGImageGetColorSpace(imageWithAlpha.CGImage) - let bitmapInfo = CGImageGetBitmapInfo(imageWithAlpha.CGImage) - let context = CGBitmapContextCreate(nil, width, height, bits, 0, colorSpace, bitmapInfo.rawValue) - let rect = CGRect(x: 0, y: 0, width: CGFloat(width) * scale, height: CGFloat(height) * scale) - CGContextBeginPath(context) - if cornerRadius == 0 { - CGContextAddRect(context, rect) - } else { - CGContextSaveGState(context) - CGContextTranslateCTM(context, rect.minX, rect.minY) - CGContextScaleCTM(context, cornerRadius, cornerRadius) - let roundedWidth = rect.size.width / cornerRadius - let roundedHeight = rect.size.height / cornerRadius - CGContextMoveToPoint(context, roundedWidth, roundedHeight/2) - CGContextAddArcToPoint(context, roundedWidth, roundedHeight, roundedWidth/2, roundedHeight, 1) - CGContextAddArcToPoint(context, 0, roundedHeight, 0, roundedHeight/2, 1) - CGContextAddArcToPoint(context, 0, 0, roundedWidth/2, 0, 1) - CGContextAddArcToPoint(context, roundedWidth, 0, roundedWidth, roundedHeight/2, 1) - CGContextRestoreGState(context) - } - CGContextClosePath(context) - CGContextClip(context) - CGContextDrawImage(context, rect, imageWithAlpha.CGImage) - guard let bitmapImage = CGBitmapContextCreateImage(context) else { - return nil - } - let image = UIImage(CGImage: bitmapImage, - scale: scale, - orientation: .Up) - UIGraphicsEndImageContext() - return image - } - - /** - creates a new image with rounded corners and border. - - - parameter cornerRadius: The corner radius. - - parameter border: The size of the border. - - parameter color: The color of the border. - - - returns: A new image - */ - public func roundCorners(cornerRadius: CGFloat, - border: CGFloat, - color: UIColor) -> UIImage? { - return roundCorners(cornerRadius)?.applyBorder(border, color: color) - } - - /** - creates a new circle image. - - - returns: A new image - */ - public func roundCornersToCircle() -> UIImage? { - let shortest = min(size.width, size.height) - return cropToSquare()?.roundCorners(shortest/2) - } - - /** - creates a new circle image with a border. - - - parameter border: CGFloat The size of the border. - - parameter color: UIColor The color of the border. - - - returns: UIImage? - */ - public func roundCornersToCircle(border border: CGFloat, color: UIColor) -> UIImage? { - let shortest = min(size.width, size.height) - return cropToSquare()?.roundCorners(shortest/2, border: border, color: color) - } - - /** - creates a new image with a border. - - - parameter border: The size of the border. - - parameter color: The color of the border. - - - returns: A new image - */ - public func applyBorder(border: CGFloat, - color: UIColor) -> UIImage? { - UIGraphicsBeginImageContextWithOptions(size, false, 0) - let width = CGImageGetWidth(CGImage) - let height = CGImageGetHeight(CGImage) - let bits = CGImageGetBitsPerComponent(CGImage) - let colorSpace = CGImageGetColorSpace(CGImage) - let bitmapInfo = CGImageGetBitmapInfo(CGImage) - let context = CGBitmapContextCreate(nil, width, height, bits, 0, colorSpace, bitmapInfo.rawValue) - var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0 - color.getRed(&red, green: &green, blue: &blue, alpha: &alpha) - CGContextSetRGBStrokeColor(context, red, green, blue, alpha) - CGContextSetLineWidth(context, border) - let rect = CGRect(x: 0, y: 0, width: size.width*scale, height: size.height*scale) - let inset = CGRectInset(rect, border*scale, border*scale) - CGContextStrokeEllipseInRect(context, inset) - CGContextDrawImage(context, inset, CGImage) - guard let bitmapImage = CGBitmapContextCreateImage(context) else { - return nil - } - let image = UIImage(CGImage: bitmapImage) - UIGraphicsEndImageContext() - return image - } - -} diff --git a/LeadKit/LeadKit/Extensions/UIImageView/UIImageView+LoadingImage.swift b/LeadKit/LeadKit/Extensions/UIImageView/UIImageView+LoadingImage.swift deleted file mode 100644 index 1e81a15a..00000000 --- a/LeadKit/LeadKit/Extensions/UIImageView/UIImageView+LoadingImage.swift +++ /dev/null @@ -1,52 +0,0 @@ -// -// UIImageView+LoadingImage.swift -// LeadKit -// -// Created by Николай Ашанин on 28.09.16. -// Copyright © 2016 Touch Instinct. All rights reserved. -// - -import UIKit -import QuartzCore - -public extension UIImageView { - - /** - loads an image from a URL. If cached, the cached image is returned. - otherwise, a place holder is used until the image from web is returned by the closure. - - - parameter url: The image URL. - - parameter placeholder: The placeholder image. - - parameter fadeIn: Weather the mage should fade in. - - parameter shouldCacheImage: Should be image cached. - - parameter closure: Returns the image from the web the first time is fetched. - - - returns: A new image - */ - public func imageFromURL(url: String, - placeholder: UIImage, - fadeIn: Bool = true, - shouldCacheImage: Bool = true, - closure: ((image: UIImage?) -> ())? = nil) { - - image = UIImage.imageFromURL(url, - placeholder: placeholder, - cacheImage: shouldCacheImage) { [weak self] - (uploadedImage: UIImage?) in - - guard let image = uploadedImage else { - return - } - self?.image = image - if fadeIn { - let transition = CATransition() - transition.duration = 0.5 - transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) - transition.type = kCATransitionFade - self?.layer.addAnimation(transition, forKey: nil) - } - closure?(image: image) - } - } - -} diff --git a/LeadKit/LeadKit/Extensions/UIStoryboard/UIStoryboard+InstantiateViewController.swift b/LeadKit/LeadKit/Extensions/UIStoryboard/UIStoryboard+InstantiateViewController.swift index 746554c9..5630bb9b 100644 --- a/LeadKit/LeadKit/Extensions/UIStoryboard/UIStoryboard+InstantiateViewController.swift +++ b/LeadKit/LeadKit/Extensions/UIStoryboard/UIStoryboard+InstantiateViewController.swift @@ -10,14 +10,14 @@ import UIKit extension UIStoryboard { /** - method for instanciating new UIViewController subclass from storyboard using storyboard identifier + method for instantiating new UIViewController subclass from storyboard using storyboard identifier provided by StoryboardIdentifierProtocol protocol implementation - returns: UIViewController subclass instance */ - public func instantiateViewController() -> T { - return instantiateViewControllerWithIdentifier(T.storyboardIdentifier()) as! T + public func instantiateViewController() -> T where T: UIViewController, T: StoryboardIdentifierProtocol { + return self.instantiateViewController(withIdentifier: T.storyboardIdentifier) as! T } } diff --git a/LeadKit/LeadKit/Extensions/UITableView/UITableView+CellRegistration.swift b/LeadKit/LeadKit/Extensions/UITableView/UITableView+CellRegistration.swift index 33e1fc95..56913de5 100644 --- a/LeadKit/LeadKit/Extensions/UITableView/UITableView+CellRegistration.swift +++ b/LeadKit/LeadKit/Extensions/UITableView/UITableView+CellRegistration.swift @@ -8,7 +8,7 @@ import UIKit -extension UITableView { +public extension UITableView { /** method which register UITableViewCell subclass for reusing in UITableView with reuse identifier provided by ReuseIdentifierProtocol protocol implementation and nib name @@ -19,9 +19,10 @@ extension UITableView { - see: ReuseIdentifierProtocol, StaticNibNameProtocol */ - public func registerNib - (forCellClass cellClass: T.Type) { - self.registerNib(UINib(nibName: T.nibName()), forCellReuseIdentifier: T.reuseIdentifier()) + public func registerNib(forCellClass cellClass: T.Type) + where T: ReuseIdentifierProtocol, T: UITableViewCell, T: StaticNibNameProtocol { + + self.register(UINib(nibName: T.nibName), forCellReuseIdentifier: T.reuseIdentifier) } /** @@ -35,10 +36,12 @@ extension UITableView { - see: ReuseIdentifierProtocol, NibNameProtocol */ - public func registerNib - (forCellClass cellClass: T.Type, forUserInterfaceIdiom interfaceIdiom: UIUserInterfaceIdiom) { + public func registerNib(forCellClass cellClass: T.Type, + forUserInterfaceIdiom interfaceIdiom: UIUserInterfaceIdiom) + where T: ReuseIdentifierProtocol, T: UITableViewCell, T: NibNameProtocol { + let nib = UINib(nibName: T.nibName(forConfiguration: interfaceIdiom)) - self.registerNib(nib, forCellReuseIdentifier: T.reuseIdentifier()) + self.register(nib, forCellReuseIdentifier: T.reuseIdentifier) } } diff --git a/LeadKit/LeadKit/Extensions/UITableView/UITableView+DequeueCustomCell.swift b/LeadKit/LeadKit/Extensions/UITableView/UITableView+DequeueCustomCell.swift index d499ee7d..c340d198 100644 --- a/LeadKit/LeadKit/Extensions/UITableView/UITableView+DequeueCustomCell.swift +++ b/LeadKit/LeadKit/Extensions/UITableView/UITableView+DequeueCustomCell.swift @@ -20,9 +20,10 @@ extension UITableView { - see: ReuseIdentifierProtocol */ - public func dequeueReusableCell - (forIndexPath indexPath: NSIndexPath) -> T { - return dequeueReusableCellWithIdentifier(T.reuseIdentifier(), forIndexPath: indexPath) as! T + public func dequeueReusableCell(forIndexPath indexPath: IndexPath) -> T + where T: UITableViewCell, T: ReuseIdentifierProtocol { + + return self.dequeueReusableCell(withIdentifier: T.reuseIdentifier, for: indexPath) as! T } } diff --git a/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultNibName.swift b/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultNibName.swift index 0ec6d6f5..b50d32ce 100644 --- a/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultNibName.swift +++ b/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultNibName.swift @@ -9,14 +9,14 @@ import UIKit extension UIView: StaticNibNameProtocol { + /** default implementation of StaticNibNameProtocol - - - returns: class name string without dot (last class path component) + + - returns: class name string */ - - public class func nibName() -> String { - return String(self.dynamicType).componentsSeparatedByString(".").last! + open class var nibName: String { + return className(of: self) } } diff --git a/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultReuseIdentifier.swift b/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultReuseIdentifier.swift index 1527d546..068cbde3 100644 --- a/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultReuseIdentifier.swift +++ b/LeadKit/LeadKit/Extensions/UIView/UIView+DefaultReuseIdentifier.swift @@ -15,8 +15,8 @@ extension UIView: ReuseIdentifierProtocol { - returns: type name string */ - public class func reuseIdentifier() -> String { - return String(self.dynamicType) + open class var reuseIdentifier: String { + return className(of: self) } } diff --git a/LeadKit/LeadKit/Extensions/UIView/UIView+LoadFromNib.swift b/LeadKit/LeadKit/Extensions/UIView/UIView+LoadFromNib.swift index b6744cdf..33fbf7a9 100644 --- a/LeadKit/LeadKit/Extensions/UIView/UIView+LoadFromNib.swift +++ b/LeadKit/LeadKit/Extensions/UIView/UIView+LoadFromNib.swift @@ -8,13 +8,13 @@ import UIKit -extension UINib { +public extension UINib { convenience public init(nibName name: String) { self.init(nibName: name, bundle: nil) } } -extension UIView { +public extension UIView { /** method which return UIView subclass instance loaded from nib using nib name provided by NibNameProtocol implementation @@ -23,8 +23,8 @@ extension UIView { - returns: UIView subclass instance */ - public static func loadFromNib - (forUserInterfaceIdiom interfaceIdiom: UIUserInterfaceIdiom) -> T { + public static func loadFromNib + (forUserInterfaceIdiom interfaceIdiom: UIUserInterfaceIdiom) -> T where T: NibNameProtocol, T: UIView { return loadFromNib(named: T.nibName(forConfiguration: interfaceIdiom)) } @@ -34,8 +34,8 @@ extension UIView { - returns: UIView subclass instance */ - public static func loadFromNib() -> T { - return loadFromNib(named: T.nibName()) + public static func loadFromNib() -> T where T: StaticNibNameProtocol, T: UIView { + return loadFromNib(named: T.nibName) } /** @@ -46,7 +46,7 @@ extension UIView { - returns: UIView subclass instance */ public static func loadFromNib(named nibName: String) -> T { - return UINib(nibName: nibName).instantiateWithOwner(nil, options: nil).first as! T + return UINib(nibName: nibName).instantiate(withOwner: nil, options: nil).first as! T } } diff --git a/LeadKit/LeadKit/Extensions/UIViewController/UIViewController+DefaultStoryboardIdentifier.swift b/LeadKit/LeadKit/Extensions/UIViewController/UIViewController+DefaultStoryboardIdentifier.swift new file mode 100644 index 00000000..2a7e2a7e --- /dev/null +++ b/LeadKit/LeadKit/Extensions/UIViewController/UIViewController+DefaultStoryboardIdentifier.swift @@ -0,0 +1,22 @@ +// +// UIViewController+DefaultStoryboardIdentifier.swift +// LeadKit +// +// Created by Ivan Smolin on 06/10/16. +// Copyright © 2016 Touch Instinct. All rights reserved. +// + +import UIKit + +extension UIViewController: StoryboardIdentifierProtocol { + + /** + default implementation of StoryboardIdentifierProtocol + + - returns: type name string + */ + open class var storyboardIdentifier: String { + return className(of: self) + } + +} diff --git a/LeadKit/LeadKit/Functions/Any+TypeName.swift b/LeadKit/LeadKit/Functions/Any+TypeName.swift new file mode 100644 index 00000000..cb726fff --- /dev/null +++ b/LeadKit/LeadKit/Functions/Any+TypeName.swift @@ -0,0 +1,19 @@ +// +// Any+TypeName.swift +// LeadKit +// +// Created by Ivan Smolin on 06/10/16. +// Copyright © 2016 Touch Instinct. All rights reserved. +// + +import Foundation + +public func className(of type: T) -> String { + let clsName = String(describing: type(of: type)) + + if let typeRange = clsName.range(of: ".Type") { + return clsName.substring(to: typeRange.lowerBound) + } else { + return clsName + } +} diff --git a/LeadKit/LeadKit/Info.plist b/LeadKit/LeadKit/Info.plist index a1497e57..abe61f5d 100644 --- a/LeadKit/LeadKit/Info.plist +++ b/LeadKit/LeadKit/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.0.3 + 0.1.0 CFBundleSignature ???? CFBundleVersion diff --git a/LeadKit/LeadKit/Protocols/NibNameProtocol.swift b/LeadKit/LeadKit/Protocols/NibNameProtocol.swift index 4e622e15..193f1bec 100644 --- a/LeadKit/LeadKit/Protocols/NibNameProtocol.swift +++ b/LeadKit/LeadKit/Protocols/NibNameProtocol.swift @@ -6,7 +6,7 @@ // Copyright © 2016 Touch Instinct. All rights reserved. // -import UIKit +import Foundation /** * protocol which ensures that specific type can return nib name of view for specific configuration diff --git a/LeadKit/LeadKit/Protocols/ReuseIdentifierProtocol.swift b/LeadKit/LeadKit/Protocols/ReuseIdentifierProtocol.swift index e45ad232..c620224f 100644 --- a/LeadKit/LeadKit/Protocols/ReuseIdentifierProtocol.swift +++ b/LeadKit/LeadKit/Protocols/ReuseIdentifierProtocol.swift @@ -15,11 +15,9 @@ public protocol AbstractReuseIdentifierProtocol { associatedtype IdentifierType /** - method which returns reuse identifier with protocol associated type - - - returns: reuse identifier + - returns: reuse identifier with protocol associated type */ - static func reuseIdentifier() -> IdentifierType + static var reuseIdentifier: IdentifierType { get } } /** @@ -27,9 +25,7 @@ public protocol AbstractReuseIdentifierProtocol { */ public protocol ReuseIdentifierProtocol: AbstractReuseIdentifierProtocol { /** - method which returns reuse identifier with string type - - - returns: reuse identifier + - returns: reuse identifier with string type */ - static func reuseIdentifier() -> String + static var reuseIdentifier: String { get } } diff --git a/LeadKit/LeadKit/Protocols/StaticNibNameProtocol.swift b/LeadKit/LeadKit/Protocols/StaticNibNameProtocol.swift index 79a7b29d..6b5ed1d1 100644 --- a/LeadKit/LeadKit/Protocols/StaticNibNameProtocol.swift +++ b/LeadKit/LeadKit/Protocols/StaticNibNameProtocol.swift @@ -13,9 +13,7 @@ import Foundation */ public protocol StaticNibNameProtocol { /** - static method which returns nib name - - returns: nib name string */ - static func nibName() -> String + static var nibName: String { get } } diff --git a/LeadKit/LeadKit/Protocols/StoryboardIdentifierProtocol.swift b/LeadKit/LeadKit/Protocols/StoryboardIdentifierProtocol.swift index 613158f2..c7a70a9d 100644 --- a/LeadKit/LeadKit/Protocols/StoryboardIdentifierProtocol.swift +++ b/LeadKit/LeadKit/Protocols/StoryboardIdentifierProtocol.swift @@ -17,5 +17,5 @@ public protocol StoryboardIdentifierProtocol { - returns: storyboard identifier string */ - static func storyboardIdentifier() -> String + static var storyboardIdentifier: String { get } } diff --git a/LeadKit/LeadKit/Protocols/ViewModelProtocol.swift b/LeadKit/LeadKit/Protocols/ViewModelProtocol.swift index 93f1b83c..a7809deb 100644 --- a/LeadKit/LeadKit/Protocols/ViewModelProtocol.swift +++ b/LeadKit/LeadKit/Protocols/ViewModelProtocol.swift @@ -21,5 +21,5 @@ public protocol AbstractViewModelProtocol { - returns: nothing */ - func setViewModel(viewModel: ViewModelType) + func setViewModel(_ viewModel: ViewModelType) } diff --git a/LeadKit/LeadKit/Structures/Api/ApiRequestParameters.swift b/LeadKit/LeadKit/Structures/Api/ApiRequestParameters.swift index 6bb00997..aaa9eb4a 100644 --- a/LeadKit/LeadKit/Structures/Api/ApiRequestParameters.swift +++ b/LeadKit/LeadKit/Structures/Api/ApiRequestParameters.swift @@ -15,17 +15,17 @@ import RxSwift */ public struct ApiRequestParameters { - let method: Alamofire.Method - let url: URLStringConvertible - let parameters: [String: AnyObject]? + let method: HTTPMethod + let url: URLConvertible + let parameters: Parameters? let encoding: ParameterEncoding - let headers: [String: String]? + let headers: HTTPHeaders? - public init(method: Alamofire.Method, - url: URLStringConvertible, - parameters: [String: AnyObject]? = nil, - encoding: ParameterEncoding = .URL, - headers: [String: String]? = nil) { + public init(url: URLConvertible, + method: HTTPMethod = .get, + parameters: Parameters? = nil, + encoding: ParameterEncoding = URLEncoding.default, + headers: HTTPHeaders? = nil) { self.method = method self.url = url diff --git a/LeadKit/LeadKitTests/LeadKitTests.swift b/LeadKit/LeadKitTests/LeadKitTests.swift index 96b03875..8e8a200f 100644 --- a/LeadKit/LeadKitTests/LeadKitTests.swift +++ b/LeadKit/LeadKitTests/LeadKitTests.swift @@ -7,7 +7,6 @@ // import XCTest -@testable import LeadKit class LeadKitTests: XCTestCase { @@ -28,7 +27,7 @@ class LeadKitTests: XCTestCase { func testPerformanceExample() { // This is an example of a performance test case. - self.measureBlock { + self.measure { // Put the code you want to measure the time of here. } } From c32f9487441fbd9a2f83680154e6b28f9b7e3bc6 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 6 Oct 2016 12:50:06 +0300 Subject: [PATCH 4/5] add some docs --- .../Extensions/CGImage/CGImage+Template.swift | 2 +- .../UIImage/UIImage+Extensions.swift | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Template.swift b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Template.swift index 96436b7c..cc524603 100644 --- a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Template.swift +++ b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Template.swift @@ -13,7 +13,7 @@ public extension CGImage { /** method which render current template CGImage into new image using given color - - parameter color: color which used to fill template image + - parameter withColor: color which used to fill template image - returns: new CGImage rendered with given color or nil if something goes wrong */ diff --git a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Extensions.swift b/LeadKit/LeadKit/Extensions/UIImage/UIImage+Extensions.swift index f278fb85..c5e4ae21 100644 --- a/LeadKit/LeadKit/Extensions/UIImage/UIImage+Extensions.swift +++ b/LeadKit/LeadKit/Extensions/UIImage/UIImage+Extensions.swift @@ -10,6 +10,15 @@ import UIKit public extension UIImage { + /** + method which creates new UIImage instance filled by given color + + - parameter color: color to fill + - parameter size: size of new image + + - returns: new instanse of UIImage with given size and color + */ + public convenience init?(color: UIColor, size: CGSize) { let cgImage = CGImage.create(color: color.cgColor, width: Int(ceil(size.width)), @@ -22,6 +31,14 @@ public extension UIImage { self.init(cgImage: image) } + /** + creates an image from a UIView. + + - parameter fromView: The source view. + + - returns A new image or nil if something goes wrong. + */ + public convenience init?(fromView view: UIView) { guard let cgImage = CGImage.create(fromView: view) else { return nil @@ -30,6 +47,13 @@ public extension UIImage { self.init(cgImage: cgImage) } + /** + method which render current template CGImage into new image using given color + + - parameter withColor: color which used to fill template image + + - returns: new CGImage rendered with given color or nil if something goes wrong + */ public func renderTemplate(withColor color: UIColor) -> UIImage? { return cgImage?.renderTemplate(withColor: color.cgColor)?.uiImage } From b10fcdc7e4ed1375a4f5c78ef8ce80bffa5d0b67 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 6 Oct 2016 14:43:47 +0300 Subject: [PATCH 5/5] code review notes --- LeadKit/LeadKit/Classes/Logging/Log.swift | 7 ++++--- LeadKit/LeadKit/Classes/Logging/LogFormatter.swift | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/LeadKit/LeadKit/Classes/Logging/Log.swift b/LeadKit/LeadKit/Classes/Logging/Log.swift index 752d8905..f1c4e4e4 100644 --- a/LeadKit/LeadKit/Classes/Logging/Log.swift +++ b/LeadKit/LeadKit/Classes/Logging/Log.swift @@ -15,14 +15,15 @@ open class Log { open let fileLogger = DDFileLogger() init() { - DDLog.add(fileLogger) DDLog.add(DDASLLogger.sharedInstance()) DDLog.add(DDTTYLogger.sharedInstance()) - DDASLLogger.sharedInstance().logFormatter = LogFormatter() - DDTTYLogger.sharedInstance().logFormatter = LogFormatter() + let logFormatter = LogFormatter() + + DDASLLogger.sharedInstance().logFormatter = logFormatter + DDTTYLogger.sharedInstance().logFormatter = logFormatter let assertionHandler = NSAssertionHandler() diff --git a/LeadKit/LeadKit/Classes/Logging/LogFormatter.swift b/LeadKit/LeadKit/Classes/Logging/LogFormatter.swift index 86a232fb..0aab1d1d 100644 --- a/LeadKit/LeadKit/Classes/Logging/LogFormatter.swift +++ b/LeadKit/LeadKit/Classes/Logging/LogFormatter.swift @@ -11,7 +11,7 @@ import CocoaLumberjack import CocoaLumberjack.DDDispatchQueueLogFormatter class LogFormatter: DDDispatchQueueLogFormatter { - let dateFormatter: DateFormatter + fileprivate let dateFormatter: DateFormatter override init() { dateFormatter = DateFormatter()