From 934831b4bfcfbee2e7ec0f5faebb2afaa929c540 Mon Sep 17 00:00:00 2001 From: suzuki_keishi Date: Tue, 30 Aug 2016 14:33:54 +0900 Subject: [PATCH] Improve compile time. --- SKPhotoBrowser/SKPagingScrollView.swift | 17 +++++++++-------- SKPhotoBrowser/SKPhotoBrowser.swift | 15 +++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/SKPhotoBrowser/SKPagingScrollView.swift b/SKPhotoBrowser/SKPagingScrollView.swift index 9232190..c081bd1 100644 --- a/SKPhotoBrowser/SKPagingScrollView.swift +++ b/SKPhotoBrowser/SKPagingScrollView.swift @@ -114,8 +114,8 @@ class SKPagingScrollView: UIScrollView { func tilePages() { guard let browser = browser else { return } - let firstIndex = getFirstIndex() - let lastIndex = getLastIndex() + let firstIndex: Int = getFirstIndex() + let lastIndex: Int = getLastIndex() visiblePages .filter({ $0.tag - pageIndexTagOffset < firstIndex || $0.tag - pageIndexTagOffset < lastIndex }) @@ -125,19 +125,20 @@ class SKPagingScrollView: UIScrollView { page.removeFromSuperview() } - let visibleSet = Set(visiblePages) - visiblePages = Array(visibleSet.subtract(recycledPages)) + let visibleSet: Set = Set(visiblePages) + let visibleSetWithoutRecycled: Set = visibleSet.subtract(recycledPages) + visiblePages = Array(visibleSetWithoutRecycled) while recycledPages.count > 2 { recycledPages.removeFirst() } - for index in firstIndex...lastIndex { + for index: Int in firstIndex...lastIndex { if visiblePages.filter({ $0.tag - pageIndexTagOffset == index }).count > 0 { continue } - let page = SKZoomingScrollView(frame: frame, browser: browser) + let page: SKZoomingScrollView = SKZoomingScrollView(frame: frame, browser: browser) page.frame = frameForPageAtIndex(index) page.tag = index + pageIndexTagOffset page.photo = browser.photos[index] @@ -146,7 +147,7 @@ class SKPagingScrollView: UIScrollView { addSubview(page) // if exists caption, insert - if let captionView = createCaptionView(index) { + if let captionView: SKCaptionView = createCaptionView(index) { captionView.frame = frameForCaptionView(captionView, index: index) captionView.alpha = browser.areControlsHidden() ? 0 : 1 addSubview(captionView) @@ -201,7 +202,7 @@ private extension SKPagingScrollView { return pageFrame } - private func createCaptionView(index: Int) -> SKCaptionView? { + func createCaptionView(index: Int) -> SKCaptionView? { guard let photo = browser?.photoAtIndex(index) where photo.caption != nil else { return nil } diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index 54ace22..fc2d310 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -376,16 +376,15 @@ internal extension SKPhotoBrowser { internal extension SKPhotoBrowser { func panGestureRecognized(sender: UIPanGestureRecognizer) { - guard let zoomingScrollView = pagingScrollView.pageDisplayedAtIndex(currentPageIndex) else { + guard let zoomingScrollView: SKZoomingScrollView = pagingScrollView.pageDisplayedAtIndex(currentPageIndex) else { return } backgroundView.hidden = true - let viewHeight = zoomingScrollView.frame.size.height - let viewHalfHeight = viewHeight/2 - - var translatedPoint = sender.translationInView(self.view) + let viewHeight: CGFloat = zoomingScrollView.frame.size.height + let viewHalfHeight: CGFloat = viewHeight/2 + var translatedPoint: CGPoint = sender.translationInView(self.view) // gesture began if sender.state == .Began { @@ -399,8 +398,8 @@ internal extension SKPhotoBrowser { translatedPoint = CGPoint(x: firstX, y: firstY + translatedPoint.y) zoomingScrollView.center = translatedPoint - let minOffset = viewHalfHeight / 4 - let offset = 1 - (zoomingScrollView.center.y > viewHalfHeight + let minOffset: CGFloat = viewHalfHeight / 4 + let offset: CGFloat = 1 - (zoomingScrollView.center.y > viewHalfHeight ? zoomingScrollView.center.y - viewHalfHeight : -(zoomingScrollView.center.y - viewHalfHeight)) / viewHalfHeight @@ -423,7 +422,7 @@ internal extension SKPhotoBrowser { let finalX: CGFloat = firstX let finalY: CGFloat = viewHalfHeight - let animationDuration = Double(abs(velocityY) * 0.0002 + 0.2) + let animationDuration: Double = Double(abs(velocityY) * 0.0002 + 0.2) UIView.beginAnimations(nil, context: nil) UIView.setAnimationDuration(animationDuration)