From d533e098f8d5e970875dcc3f16588f9ec3674ed8 Mon Sep 17 00:00:00 2001 From: nikAshanin Date: Thu, 6 Apr 2017 14:23:16 +0300 Subject: [PATCH] tabledirector extensions added --- LeadKit/LeadKit.xcodeproj/project.pbxproj | 12 ++++ LeadKit/LeadKit/Classes/Views/XibView.swift | 2 +- .../TableDirector+Extensions.swift | 72 +++++++++++++++++++ .../Extensions/UIView/UIView+Rotation.swift | 2 +- LeadKit/LeadKit/Info.plist | 2 +- LeadKit/Podfile | 3 +- LeadKit/Podfile.lock | 5 +- 7 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 LeadKit/LeadKit/Extensions/TableDirector/TableDirector+Extensions.swift diff --git a/LeadKit/LeadKit.xcodeproj/project.pbxproj b/LeadKit/LeadKit.xcodeproj/project.pbxproj index 8465b465..e4fee7cf 100644 --- a/LeadKit/LeadKit.xcodeproj/project.pbxproj +++ b/LeadKit/LeadKit.xcodeproj/project.pbxproj @@ -74,6 +74,7 @@ CAA707D51E2E614E0022D732 /* ModuleConfigurator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAA707D41E2E614E0022D732 /* ModuleConfigurator.swift */; }; CAA707D71E2E616D0022D732 /* BaseViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAA707D61E2E616D0022D732 /* BaseViewModel.swift */; }; CAA707D91E2E61A50022D732 /* ConfigurableController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAA707D81E2E61A50022D732 /* ConfigurableController.swift */; }; + CAE698C21E965B47000394B0 /* TableDirector+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAE698C01E965B47000394B0 /* TableDirector+Extensions.swift */; }; E126CBB31DB68DDA00E1B2F8 /* UICollectionView+CellRegistration.swift in Sources */ = {isa = PBXBuildFile; fileRef = E126CBB21DB68DDA00E1B2F8 /* UICollectionView+CellRegistration.swift */; }; EF2921A61E165DF400E8F43B /* TimeInterval+DateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF2921A51E165DF400E8F43B /* TimeInterval+DateComponents.swift */; }; EF5FB5691E0141610030E4BE /* UIView+Rotation.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF5FB5681E0141610030E4BE /* UIView+Rotation.swift */; }; @@ -163,6 +164,7 @@ CAA707D41E2E614E0022D732 /* ModuleConfigurator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModuleConfigurator.swift; sourceTree = ""; }; CAA707D61E2E616D0022D732 /* BaseViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseViewModel.swift; sourceTree = ""; }; CAA707D81E2E61A50022D732 /* ConfigurableController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigurableController.swift; sourceTree = ""; }; + CAE698C01E965B47000394B0 /* TableDirector+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "TableDirector+Extensions.swift"; path = "TableDirector/TableDirector+Extensions.swift"; sourceTree = ""; }; CC832342120EAD568C9F7FC3 /* Pods-LeadKitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKitTests/Pods-LeadKitTests.debug.xcconfig"; sourceTree = ""; }; E126CBB21DB68DDA00E1B2F8 /* UICollectionView+CellRegistration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UICollectionView+CellRegistration.swift"; path = "UICollectionView/UICollectionView+CellRegistration.swift"; sourceTree = ""; }; EF2921A51E165DF400E8F43B /* TimeInterval+DateComponents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TimeInterval+DateComponents.swift"; sourceTree = ""; }; @@ -450,6 +452,7 @@ 78CFEE441C5C45E500F50370 /* Extensions */ = { isa = PBXGroup; children = ( + CAE698BF1E965AE9000394B0 /* TableDirector */, 786D78E61D53C355006B2CEA /* Alamofire */, 780D23441DA416E80084620D /* CGContext */, 67788F9D1E6965F800484DEE /* CGFloat */, @@ -558,6 +561,14 @@ name = UIDevice; sourceTree = ""; }; + CAE698BF1E965AE9000394B0 /* TableDirector */ = { + isa = PBXGroup; + children = ( + CAE698C01E965B47000394B0 /* TableDirector+Extensions.swift */, + ); + name = TableDirector; + sourceTree = ""; + }; E126CBB11DB68D9A00E1B2F8 /* UICollectionView */ = { isa = PBXGroup; children = ( @@ -857,6 +868,7 @@ 787682FA1CAD40C300532AB3 /* StaticEstimatedViewHeightProtocol.swift in Sources */, CA1FE7091E27D7DE00968901 /* UIDevice+Extensions.swift in Sources */, 78A74EA91C6B373700FE9724 /* UIView+DefaultNibName.swift in Sources */, + CAE698C21E965B47000394B0 /* TableDirector+Extensions.swift in Sources */, CAA707D91E2E61A50022D732 /* ConfigurableController.swift in Sources */, 7884DB9C1DC1439200E52A63 /* UserDefaults+MappableDataTypes.swift in Sources */, CAA707D71E2E616D0022D732 /* BaseViewModel.swift in Sources */, diff --git a/LeadKit/LeadKit/Classes/Views/XibView.swift b/LeadKit/LeadKit/Classes/Views/XibView.swift index 0f79194e..2bc4d5d2 100644 --- a/LeadKit/LeadKit/Classes/Views/XibView.swift +++ b/LeadKit/LeadKit/Classes/Views/XibView.swift @@ -51,7 +51,7 @@ open class XibView: UIView { frame = CGRect(origin: frame.origin, size: view.frame.size) view.autoresizingMask = [.flexibleWidth, .flexibleHeight] - + addSubview(view) } diff --git a/LeadKit/LeadKit/Extensions/TableDirector/TableDirector+Extensions.swift b/LeadKit/LeadKit/Extensions/TableDirector/TableDirector+Extensions.swift new file mode 100644 index 00000000..4e97607b --- /dev/null +++ b/LeadKit/LeadKit/Extensions/TableDirector/TableDirector+Extensions.swift @@ -0,0 +1,72 @@ +// +// Copyright (c) 2017 Touch Instinct +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +import TableKit + +extension TableDirector { + + @discardableResult + func replace(section: TableSection, atIndex index: Int, reload: Bool = true) -> Self { + if index < sections.count { + remove(sectionAt: index) + } + insert(section: section, atIndex: index) + if reload { + self.reload(sectionAtIndex: index) + } + return self + } + + @discardableResult + func reload(sectionAtIndex index: Int, with animation: UITableViewRowAnimation = .none) -> Self { + let action = { [tableView] in + if index < tableView?.numberOfSections ?? 0 { + tableView?.reloadSections([index], with: animation) + } else { + tableView?.reloadData() + } + } + if animation == .none { + UIView.performWithoutAnimation(action) + } else { + action() + } + return self + } + + @discardableResult + func replace(withSections sections: [TableSection]) -> Self { + clear().append(sections: sections).reload() + return self + } + + @discardableResult + func replace(withSection section: TableSection) -> Self { + return replace(withSections: [section]) + } + + @discardableResult + func replace(withRows rows: [Row]) -> Self { + return replace(withSection: TableSection(rows: rows)) + } + +} diff --git a/LeadKit/LeadKit/Extensions/UIView/UIView+Rotation.swift b/LeadKit/LeadKit/Extensions/UIView/UIView+Rotation.swift index a1c9c283..b59f2530 100644 --- a/LeadKit/LeadKit/Extensions/UIView/UIView+Rotation.swift +++ b/LeadKit/LeadKit/Extensions/UIView/UIView+Rotation.swift @@ -36,7 +36,7 @@ extension UIView { public func startZRotation(duration: CFTimeInterval = 1, repeatCount: Float = Float.infinity, clockwise: Bool = true) { let animation = CABasicAnimation(keyPath: UIView.rotationKeyPath) let direction = clockwise ? 1.0 : -1.0 - animation.toValue = NSNumber(value: M_PI * 2 * direction) + animation.toValue = NSNumber(value: .pi * 2 * direction) animation.duration = duration animation.isCumulative = true animation.repeatCount = repeatCount diff --git a/LeadKit/LeadKit/Info.plist b/LeadKit/LeadKit/Info.plist index c18984fb..98ddb10b 100644 --- a/LeadKit/LeadKit/Info.plist +++ b/LeadKit/LeadKit/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.4.4 + 0.4.7 CFBundleSignature ???? CFBundleVersion diff --git a/LeadKit/Podfile b/LeadKit/Podfile index 4918ed11..76cddc6c 100644 --- a/LeadKit/Podfile +++ b/LeadKit/Podfile @@ -10,7 +10,8 @@ target 'LeadKit' do pod "RxAlamofire", '3.0.0' pod "ObjectMapper", '~> 2.1' pod "Toast-Swift", '~> 2.0.0' - + pod "TableKit", '~> 2.3.1' + target 'LeadKitTests' do inherit! :search_paths # Pods for testing diff --git a/LeadKit/Podfile.lock b/LeadKit/Podfile.lock index f9399332..d02ce890 100644 --- a/LeadKit/Podfile.lock +++ b/LeadKit/Podfile.lock @@ -12,6 +12,7 @@ PODS: - RxCocoa (3.2.0): - RxSwift (~> 3.1) - RxSwift (3.2.0) + - TableKit (2.3.1) - Toast-Swift (2.0.0) DEPENDENCIES: @@ -20,6 +21,7 @@ DEPENDENCIES: - RxAlamofire (= 3.0.0) - RxCocoa (= 3.2.0) - RxSwift (= 3.2.0) + - TableKit (~> 2.3.1) - Toast-Swift (~> 2.0.0) SPEC CHECKSUMS: @@ -29,8 +31,9 @@ SPEC CHECKSUMS: RxAlamofire: 0b1fa48f545fffe7f7a28af2086bcaa3b5946cc9 RxCocoa: ccdf43101a70407097a29082f648ba1676075b30 RxSwift: 46574f70d416b7923c237195939cc488a7fbf3a0 + TableKit: 02e041b443f75fa3e9f1ee6024d4b256305bd904 Toast-Swift: 5b2f8f720f7e78e48511f693df1f9c9a6e38a25a -PODFILE CHECKSUM: ee07f67e4cce90b2d448e0c18941bc51ab6180cc +PODFILE CHECKSUM: c85ee069c7ba0c53c44a486be3daf0ff5ed4e9fa COCOAPODS: 1.2.0