From a2d3ac60f63dff10b67926d46231b93d3704513f Mon Sep 17 00:00:00 2001 From: Michael Skiba Date: Wed, 20 Jul 2016 10:30:22 -0400 Subject: [PATCH] linted --- RIGImageGallery.xcodeproj/project.pbxproj | 35 ++++++++++++++++++- .../RIGAutoCenteringScrollView.swift | 4 +-- .../RIGImageGalleryViewController.swift | 19 +++++----- .../View Controller/ViewController.swift | 2 +- .../AutoCenteringScrollViewTests.swift | 6 ++-- .../ImageGalleryViewControllerTests.swift | 5 ++- .../SingleImageViewControllerTests.swift | 2 +- RIGImageGalleryTests/TestingExtensions.swift | 2 +- 8 files changed, 56 insertions(+), 19 deletions(-) diff --git a/RIGImageGallery.xcodeproj/project.pbxproj b/RIGImageGallery.xcodeproj/project.pbxproj index 03e26b8..71160ce 100644 --- a/RIGImageGallery.xcodeproj/project.pbxproj +++ b/RIGImageGallery.xcodeproj/project.pbxproj @@ -223,6 +223,7 @@ 72060F4C1D2FFA6C001281E0 /* Sources */, 72060F4D1D2FFA6C001281E0 /* Frameworks */, 72060F4E1D2FFA6C001281E0 /* Resources */, + 7264CA1D1D3FC01C00033FC4 /* Swiftlint */, ); buildRules = ( ); @@ -242,6 +243,7 @@ 72A828061C68F24500B25CEE /* Frameworks */, 72A828071C68F24500B25CEE /* Resources */, 72BA263B1C6B97A500F1FE22 /* Embed Frameworks */, + 7264CA1E1D3FC02E00033FC4 /* SwiftLint */, ); buildRules = ( ); @@ -307,8 +309,8 @@ projectDirPath = ""; projectRoot = ""; targets = ( - 72A828081C68F24500B25CEE /* RIGImageGalleryDemo */, 72BA26511C6B985900F1FE22 /* RIGImageGallery */, + 72A828081C68F24500B25CEE /* RIGImageGalleryDemo */, 72060F4F1D2FFA6C001281E0 /* RIGImageGalleryTests */, ); }; @@ -340,6 +342,37 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 7264CA1D1D3FC01C00033FC4 /* Swiftlint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = Swiftlint; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + }; + 7264CA1E1D3FC02E00033FC4 /* SwiftLint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = SwiftLint; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 72060F4C1D2FFA6C001281E0 /* Sources */ = { isa = PBXSourcesBuildPhase; diff --git a/RIGImageGallery/RIGAutoCenteringScrollView.swift b/RIGImageGallery/RIGAutoCenteringScrollView.swift index f9a4ce2..1a7c532 100644 --- a/RIGImageGallery/RIGAutoCenteringScrollView.swift +++ b/RIGImageGallery/RIGAutoCenteringScrollView.swift @@ -120,14 +120,14 @@ private extension RIGAutoCenteringScrollView { let vertical: CGFloat let horizontal: CGFloat - if (contentSize.width < adjustedSize.width) { + if contentSize.width < adjustedSize.width { horizontal = floor((adjustedSize.width - contentSize.width) * 0.5) } else { horizontal = 0 } - if (contentSize.height < adjustedSize.height) { + if contentSize.height < adjustedSize.height { vertical = floor((adjustedSize.height - contentSize.height) * 0.5) } else { diff --git a/RIGImageGallery/RIGImageGalleryViewController.swift b/RIGImageGallery/RIGImageGalleryViewController.swift index eb783e4..286c4f7 100644 --- a/RIGImageGallery/RIGImageGalleryViewController.swift +++ b/RIGImageGallery/RIGImageGalleryViewController.swift @@ -10,24 +10,29 @@ import UIKit public class RIGImageGalleryViewController: UIPageViewController { + public typealias GalleryPositionUpdateHandler = (gallery: RIGImageGalleryViewController, position: Int, total: Int) -> () + public typealias ActionButtonPressedHandler = (gallery: RIGImageGalleryViewController, item: RIGImageGalleryItem) -> () + public typealias GalleryEventHandler = RIGImageGalleryViewController -> () + public typealias IndexUpdateHandler = Int -> () + /// An optional closure to execute if the action button is tapped - public var actionButtonHandler: ((gallery: RIGImageGalleryViewController, item:RIGImageGalleryItem) -> ())? + public var actionButtonHandler: ActionButtonPressedHandler? /// An optional closure to allow cutom trait collection change handling - public var traitCollectionChangeHandler: (RIGImageGalleryViewController -> ())? { + public var traitCollectionChangeHandler: GalleryEventHandler? { didSet { traitCollectionChangeHandler?(self) } } /// An optional closure to execute when the active index is updated - public var indexUpdateHandler: (Int -> ())? + public var indexUpdateHandler: IndexUpdateHandler? /// An optional closure to handle dismissing the gallery, if this is nil the view will call `dismissViewControllerAnimated(true, completion: nil)`, if this is non-nil, the view controller will not dismiss itself - public var dismissHandler: (RIGImageGalleryViewController -> ())? + public var dismissHandler: GalleryEventHandler? /// An optional closure to handle updating the count text - public var countUpdateHandler: ((gallery: RIGImageGalleryViewController, position: Int, total: Int) -> ())? { + public var countUpdateHandler: GalleryPositionUpdateHandler? { didSet { updateCountText() } @@ -104,8 +109,6 @@ public class RIGImageGalleryViewController: UIPageViewController { /** A convenience initializer to return a configured empty RIGImageGalleryViewController - - - returns: the RIGImageGalleryViewController */ public convenience init() { self.init(images: []) @@ -115,8 +118,6 @@ public class RIGImageGalleryViewController: UIPageViewController { A convenience initializer to return a configured RIGImageGalleryViewController with an array of images - parameter images: The images to use in the gallery - - - returns: the RIGImageGalleryViewController */ public convenience init(images: [RIGImageGalleryItem]) { self.init(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: [UIPageViewControllerOptionInterPageSpacingKey: 20]) diff --git a/RIGImageGalleryDemo/View Controller/ViewController.swift b/RIGImageGalleryDemo/View Controller/ViewController.swift index ff5de35..4790c14 100644 --- a/RIGImageGalleryDemo/View Controller/ViewController.swift +++ b/RIGImageGalleryDemo/View Controller/ViewController.swift @@ -66,7 +66,7 @@ private extension ViewController { dismissViewControllerAnimated(true, completion: nil) } - func actionButtonHandler(_: RIGImageGalleryViewController,galleryItem: RIGImageGalleryItem) { + func actionButtonHandler(_: RIGImageGalleryViewController, galleryItem: RIGImageGalleryItem) { } func updateCount(gallery: RIGImageGalleryViewController, position: Int, total: Int) { diff --git a/RIGImageGalleryTests/AutoCenteringScrollViewTests.swift b/RIGImageGalleryTests/AutoCenteringScrollViewTests.swift index ac30131..f9a36e2 100644 --- a/RIGImageGalleryTests/AutoCenteringScrollViewTests.swift +++ b/RIGImageGalleryTests/AutoCenteringScrollViewTests.swift @@ -12,16 +12,16 @@ import XCTest class AutoCenteringScrollViewTests: XCTestCase { var scrollView = RIGAutoCenteringScrollView(frame: CGRect()) - + override func setUp() { super.setUp() scrollView = RIGAutoCenteringScrollView(frame: CGRect(x: 0, y: 0, width: 400, height: 400)) } - + override func tearDown() { super.tearDown() } - + func testSettingInsets() { XCTAssertEqual(scrollView.zoomScale, 1, "The scroll view's zoom scale should start at 1") XCTAssertEqual(scrollView.minimumZoomScale, 1, "The scroll view's min zoom scale should start at 1") diff --git a/RIGImageGalleryTests/ImageGalleryViewControllerTests.swift b/RIGImageGalleryTests/ImageGalleryViewControllerTests.swift index bbf9bda..5028105 100644 --- a/RIGImageGalleryTests/ImageGalleryViewControllerTests.swift +++ b/RIGImageGalleryTests/ImageGalleryViewControllerTests.swift @@ -23,7 +23,7 @@ class ImageGalleryViewControllerTests: XCTestCase { imageGallery.viewWillLayoutSubviews() imageGallery.viewWillAppear(false) } - + override func tearDown() { // Put teardown code here. This method is called after the invocation of each test method in the class. super.tearDown() @@ -81,11 +81,14 @@ class ImageGalleryViewControllerTests: XCTestCase { func testPageViewController() { XCTAssertNotNil(imageGallery.viewControllers?.first as? RIGSingleImageViewController) + // swiftlint:disable:next force_cast let firstView = imageGallery.viewControllers!.first as! RIGSingleImageViewController XCTAssertEqual(firstView.viewerItem, imageGallery.images.first, "The first view should have the first image in the gallery") XCTAssertNil(imageGallery.pageViewController(imageGallery, viewControllerBeforeViewController: firstView), "The view before the first view should be nil") + // swiftlint:disable:next force_cast let secondView = imageGallery.pageViewController(imageGallery, viewControllerAfterViewController: firstView) as! RIGSingleImageViewController XCTAssertEqual(secondView.viewerItem, imageGallery.images[1], "The second view should have the second image in the gallery") + // swiftlint:disable:next force_cast XCTAssertEqual((imageGallery.pageViewController(imageGallery, viewControllerBeforeViewController: secondView) as! RIGSingleImageViewController).viewerItem, firstView.viewerItem, "the view before the second view should be the first view, which is testable by comparing viewer items") let thirdView = imageGallery.pageViewController(imageGallery, viewControllerAfterViewController: secondView)! let fourthView = imageGallery.pageViewController(imageGallery, viewControllerAfterViewController: thirdView)! diff --git a/RIGImageGalleryTests/SingleImageViewControllerTests.swift b/RIGImageGalleryTests/SingleImageViewControllerTests.swift index 4dc4232..190cb29 100644 --- a/RIGImageGalleryTests/SingleImageViewControllerTests.swift +++ b/RIGImageGalleryTests/SingleImageViewControllerTests.swift @@ -14,7 +14,7 @@ class SingleImageViewControllerTests: XCTestCase { override func setUp() { super.setUp() } - + override func tearDown() { super.tearDown() } diff --git a/RIGImageGalleryTests/TestingExtensions.swift b/RIGImageGalleryTests/TestingExtensions.swift index d4845ea..65df76d 100644 --- a/RIGImageGalleryTests/TestingExtensions.swift +++ b/RIGImageGalleryTests/TestingExtensions.swift @@ -30,5 +30,5 @@ extension UIImage { return genericImage } - + }