From 77caccac17ca7f0801f0ccd1e25779f2468a4b71 Mon Sep 17 00:00:00 2001 From: yoloabdo Date: Tue, 5 Jun 2018 13:30:07 +0200 Subject: [PATCH 1/2] removing cycles --- .../ImageSlideshow.xcodeproj/project.pbxproj | 8 ++- .../xcschemes/ImageSlideshow-Example.xcscheme | 4 +- .../ImageSlideshow_framework.xcscheme | 4 +- .../ImageSlideshow/TableViewController.swift | 2 +- Example/Podfile.lock | 16 ++--- .../Classes/Core/ActivityIndicator.swift | 4 +- .../Classes/Core/ImageSlideshow.swift | 64 +++++++++---------- .../Classes/Core/ImageSlideshowItem.swift | 10 +-- .../Classes/Core/PageIndicator.swift | 2 +- .../Core/ZoomAnimatedTransitioning.swift | 4 +- .../Classes/InputSources/AFURLSource.swift | 4 +- 11 files changed, 61 insertions(+), 61 deletions(-) diff --git a/Example/ImageSlideshow.xcodeproj/project.pbxproj b/Example/ImageSlideshow.xcodeproj/project.pbxproj index ab85b5bf..fe26e39b 100644 --- a/Example/ImageSlideshow.xcodeproj/project.pbxproj +++ b/Example/ImageSlideshow.xcodeproj/project.pbxproj @@ -57,9 +57,9 @@ 8AA07A6EDAC622F1407E6C80 /* Pods_ImageSlideshow_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ImageSlideshow_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D007954E2043262C0053E25F /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; D0083DCD1EB739E700126B21 /* ActivityIndicator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ActivityIndicator.swift; path = ../../ImageSlideshow/Classes/Core/ActivityIndicator.swift; sourceTree = ""; }; - D0B974AF202738F6006217CF /* PageIndicator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PageIndicator.swift; path = ../../ImageSlideshow/Classes/Core/PageIndicator.swift; sourceTree = ""; }; D00C7A2520B4C0A000E5725B /* ic_cross_white@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "ic_cross_white@3x.png"; path = "../../../ImageSlideshow/Assets/ic_cross_white@3x.png"; sourceTree = ""; }; D00C7A2620B4C0A100E5725B /* ic_cross_white@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "ic_cross_white@2x.png"; path = "../../../ImageSlideshow/Assets/ic_cross_white@2x.png"; sourceTree = ""; }; + D0B974AF202738F6006217CF /* PageIndicator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PageIndicator.swift; path = ../../ImageSlideshow/Classes/Core/PageIndicator.swift; sourceTree = ""; }; D0E8A9E21D97EB6D007EC517 /* ImageSlideshow.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ImageSlideshow.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D0E8A9E41D97EB6D007EC517 /* ImageSlideshow_framework.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageSlideshow_framework.h; sourceTree = ""; }; D0E8A9E51D97EB6D007EC517 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -294,7 +294,7 @@ attributes = { LastSwiftMigration = 0700; LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 0940; ORGANIZATIONNAME = CocoaPods; TargetAttributes = { 607FACCF1AFB9204008FA782 = { @@ -489,12 +489,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 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_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -543,12 +545,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 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_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; diff --git a/Example/ImageSlideshow.xcodeproj/xcshareddata/xcschemes/ImageSlideshow-Example.xcscheme b/Example/ImageSlideshow.xcodeproj/xcshareddata/xcschemes/ImageSlideshow-Example.xcscheme index fa90738b..4218952b 100644 --- a/Example/ImageSlideshow.xcodeproj/xcshareddata/xcschemes/ImageSlideshow-Example.xcscheme +++ b/Example/ImageSlideshow.xcodeproj/xcshareddata/xcschemes/ImageSlideshow-Example.xcscheme @@ -1,6 +1,6 @@ @@ -37,7 +36,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Example/ImageSlideshow/TableViewController.swift b/Example/ImageSlideshow/TableViewController.swift index 4a00d530..f226834b 100644 --- a/Example/ImageSlideshow/TableViewController.swift +++ b/Example/ImageSlideshow/TableViewController.swift @@ -61,6 +61,6 @@ class TableViewController: UITableViewController { } } - self.present(fullScreenController, animated: true, completion: nil) + present(fullScreenController, animated: true, completion: nil) } } diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 255d3aaa..5a6541f1 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -17,19 +17,19 @@ PODS: - Alamofire (4.5.1) - AlamofireImage (3.3.0): - Alamofire (~> 4.5) - - ImageSlideshow (1.5.3): - - ImageSlideshow/Core (= 1.5.3) - - ImageSlideshow/AFURL (1.5.3): + - ImageSlideshow (1.6): + - ImageSlideshow/Core (= 1.6) + - ImageSlideshow/AFURL (1.6): - AFNetworking (~> 3.0) - ImageSlideshow/Core - - ImageSlideshow/Alamofire (1.5.3): + - ImageSlideshow/Alamofire (1.6): - AlamofireImage (~> 3.0) - ImageSlideshow/Core - - ImageSlideshow/Core (1.5.3) - - ImageSlideshow/Kingfisher (1.5.3): + - ImageSlideshow/Core (1.6) + - ImageSlideshow/Kingfisher (1.6): - ImageSlideshow/Core - Kingfisher (> 3.0) - - ImageSlideshow/SDWebImage (1.5.3): + - ImageSlideshow/SDWebImage (1.6): - ImageSlideshow/Core - SDWebImage (< 5.0, >= 3.7) - Kingfisher (4.0.1) @@ -60,7 +60,7 @@ SPEC CHECKSUMS: AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67 Alamofire: 2d95912bf4c34f164fdfc335872e8c312acaea4a AlamofireImage: 2e784dc5d00f04903a52c1d169181469c805c3df - ImageSlideshow: 20d32ba26ab5b895e84d37e91ee2c18fc358a449 + ImageSlideshow: f06168438862e8b2c901b2066f3abb5d20f7dd50 Kingfisher: b771785e9461ed4b8686d40e7145f9e58100cb24 SDWebImage: 098e97e6176540799c27e804c96653ee0833d13c diff --git a/ImageSlideshow/Classes/Core/ActivityIndicator.swift b/ImageSlideshow/Classes/Core/ActivityIndicator.swift index 0dd4b093..9508ee83 100644 --- a/ImageSlideshow/Classes/Core/ActivityIndicator.swift +++ b/ImageSlideshow/Classes/Core/ActivityIndicator.swift @@ -31,11 +31,11 @@ extension UIActivityIndicatorView: ActivityIndicatorView { } public func show() { - self.startAnimating() + startAnimating() } public func hide() { - self.stopAnimating() + stopAnimating() } } diff --git a/ImageSlideshow/Classes/Core/ImageSlideshow.swift b/ImageSlideshow/Classes/Core/ImageSlideshow.swift index a29c5274..ea86e343 100644 --- a/ImageSlideshow/Classes/Core/ImageSlideshow.swift +++ b/ImageSlideshow/Classes/Core/ImageSlideshow.swift @@ -49,7 +49,7 @@ open class ImageSlideshow: UIView { /// Activity indicator shown when loading image open var activityIndicator: ActivityIndicatorFactory? { didSet { - self.reloadScrollView() + reloadScrollView() } } @@ -130,8 +130,8 @@ open class ImageSlideshow: UIView { /// Enables/disables infinite scrolling between images open var circular = true { didSet { - if self.images.count > 0 { - self.setImageInputs(self.images) + if images.count > 0 { + setImageInputs(images) } } } @@ -139,29 +139,29 @@ open class ImageSlideshow: UIView { /// Enables/disables user interactions open var draggingEnabled = true { didSet { - self.scrollView.isUserInteractionEnabled = draggingEnabled + scrollView.isUserInteractionEnabled = draggingEnabled } } /// Enables/disables zoom open var zoomEnabled = false { didSet { - self.reloadScrollView() + reloadScrollView() } } /// Maximum zoom scale open var maximumScale: CGFloat = 2.0 { didSet { - self.reloadScrollView() + reloadScrollView() } } /// Image change interval, zero stops the auto-scrolling open var slideshowInterval = 0.0 { didSet { - self.slideshowTimer?.invalidate() - self.slideshowTimer = nil + slideshowTimer?.invalidate() + slideshowTimer = nil setTimerIfNeeded() } } @@ -215,7 +215,7 @@ open class ImageSlideshow: UIView { scrollView.bounces = true scrollView.showsHorizontalScrollIndicator = false scrollView.showsVerticalScrollIndicator = false - scrollView.autoresizingMask = self.autoresizingMask + scrollView.autoresizingMask = autoresizingMask if #available(iOS 11.0, *) { scrollView.contentInsetAdjustmentBehavior = .never } @@ -235,7 +235,7 @@ open class ImageSlideshow: UIView { open override func removeFromSuperview() { super.removeFromSuperview() - self.pauseTimer() + pauseTimer() } open override func layoutSubviews() { @@ -250,15 +250,15 @@ open class ImageSlideshow: UIView { open func layoutPageControl() { if let pageIndicatorView = pageIndicator?.view { - pageIndicatorView.isHidden = self.images.count < 2 + pageIndicatorView.isHidden = images.count < 2 var edgeInsets: UIEdgeInsets = UIEdgeInsets.zero if #available(iOS 11.0, *) { - edgeInsets = self.safeAreaInsets + edgeInsets = safeAreaInsets } pageIndicatorView.sizeToFit() - pageIndicatorView.frame = pageIndicatorPosition.indicatorFrame(for: self.frame, indicatorSize: pageIndicatorView.frame.size, edgeInsets: edgeInsets) + pageIndicatorView.frame = pageIndicatorPosition.indicatorFrame(for: frame, indicatorSize: pageIndicatorView.frame.size, edgeInsets: edgeInsets) } } @@ -270,7 +270,7 @@ open class ImageSlideshow: UIView { scrollView.frame = CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height - scrollViewBottomPadding) scrollView.contentSize = CGSize(width: scrollView.frame.size.width * CGFloat(scrollViewImages.count), height: scrollView.frame.size.height) - for (index, view) in self.slideshowItems.enumerated() { + for (index, view) in slideshowItems.enumerated() { if !view.zoomInInitially { view.zoomOut() } @@ -283,15 +283,15 @@ open class ImageSlideshow: UIView { /// reloads scroll view with latest slideshow items func reloadScrollView() { // remove previous slideshow items - for view in self.slideshowItems { + for view in slideshowItems { view.removeFromSuperview() } - self.slideshowItems = [] + slideshowItems = [] var i = 0 for image in scrollViewImages { - let item = ImageSlideshowItem(image: image, zoomEnabled: self.zoomEnabled, activityIndicator: self.activityIndicator?.create(), maximumScale: maximumScale) - item.imageView.contentMode = self.contentScaleMode + let item = ImageSlideshowItem(image: image, zoomEnabled: zoomEnabled, activityIndicator: activityIndicator?.create(), maximumScale: maximumScale) + item.imageView.contentMode = contentScaleMode slideshowItems.append(item) scrollView.addSubview(item) i += 1 @@ -312,7 +312,7 @@ open class ImageSlideshow: UIView { for i in 0.. 1 { @@ -348,9 +348,9 @@ open class ImageSlideshow: UIView { scImages.append(first) } - self.scrollViewImages = scImages + scrollViewImages = scImages } else { - self.scrollViewImages = images + scrollViewImages = images } reloadScrollView() @@ -372,7 +372,7 @@ open class ImageSlideshow: UIView { pageOffset += 1 } - self.setScrollViewPage(pageOffset, animated: animated) + setScrollViewPage(pageOffset, animated: animated) } /** @@ -382,8 +382,8 @@ open class ImageSlideshow: UIView { */ open func setScrollViewPage(_ newScrollViewPage: Int, animated: Bool) { if scrollViewPage < scrollViewImages.count { - self.scrollView.scrollRectToVisible(CGRect(x: scrollView.frame.size.width * CGFloat(newScrollViewPage), y: 0, width: scrollView.frame.size.width, height: scrollView.frame.size.height), animated: animated) - self.setCurrentPageForScrollViewPage(newScrollViewPage) + scrollView.scrollRectToVisible(CGRect(x: scrollView.frame.size.width * CGFloat(newScrollViewPage), y: 0, width: scrollView.frame.size.width, height: scrollView.frame.size.height), animated: animated) + setCurrentPageForScrollViewPage(newScrollViewPage) } } @@ -401,7 +401,7 @@ open class ImageSlideshow: UIView { nextPage = 0 } - self.setScrollViewPage(nextPage, animated: true) + setScrollViewPage(nextPage, animated: true) } fileprivate func setCurrentPageForScrollViewPage(_ page: Int) { @@ -448,12 +448,12 @@ open class ImageSlideshow: UIView { @available(*, deprecated, message: "use pauseTimer instead") open func pauseTimerIfNeeded() { - self.pauseTimer() + pauseTimer() } @available(*, deprecated, message: "use unpauseTimer instead") open func unpauseTimerIfNeeded() { - self.unpauseTimer() + unpauseTimer() } /** @@ -468,8 +468,8 @@ open class ImageSlideshow: UIView { self?.setCurrentPage(page, animated: false) } - fullscreen.initialPage = self.currentPage - fullscreen.inputs = self.images + fullscreen.initialPage = currentPage + fullscreen.inputs = images slideshowTransitioningDelegate = ZoomAnimatedTransitioningDelegate(slideshowView: self, slideshowController: fullscreen) fullscreen.transitioningDelegate = slideshowTransitioningDelegate controller.present(fullscreen, animated: true, completion: nil) @@ -479,7 +479,7 @@ open class ImageSlideshow: UIView { @objc private func pageControlValueChanged() { if let currentPage = pageIndicator?.page { - self.setCurrentPage(currentPage, animated: true) + setCurrentPage(currentPage, animated: true) } } } diff --git a/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift b/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift index 760d51d4..984fdbe3 100644 --- a/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift +++ b/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift @@ -125,12 +125,12 @@ open class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate { isLoading = true imageReleased = false activityIndicator?.show() - image.load(to: self.imageView) { image in + image.load(to: self.imageView) {[weak self] image in // set image to nil if there was a release request during the image load - self.imageView.image = self.imageReleased ? nil : image - self.activityIndicator?.hide() - self.loadFailed = image == nil - self.isLoading = false + self?.imageView.image = self?.imageReleased ? nil : image + self?.activityIndicator?.hide() + self?.loadFailed = image == nil + self?.isLoading = false } } } diff --git a/ImageSlideshow/Classes/Core/PageIndicator.swift b/ImageSlideshow/Classes/Core/PageIndicator.swift index cd9e71d8..8cba823b 100644 --- a/ImageSlideshow/Classes/Core/PageIndicator.swift +++ b/ImageSlideshow/Classes/Core/PageIndicator.swift @@ -79,6 +79,6 @@ public class LabelPageIndicator: UILabel, PageIndicatorView { public override func sizeToFit() { let maximumString = String(repeating: "8", count: numberOfPages) as NSString - self.frame.size = maximumString.size(withAttributes: [.font: self.font]) + self.frame.size = maximumString.size(withAttributes: [.font: font]) } } diff --git a/ImageSlideshow/Classes/Core/ZoomAnimatedTransitioning.swift b/ImageSlideshow/Classes/Core/ZoomAnimatedTransitioning.swift index 74376d6e..8fdf11ad 100644 --- a/ImageSlideshow/Classes/Core/ZoomAnimatedTransitioning.swift +++ b/ImageSlideshow/Classes/Core/ZoomAnimatedTransitioning.swift @@ -223,9 +223,9 @@ class ZoomInAnimator: ZoomAnimator, UIViewControllerAnimatedTransitioning { fromViewController.view.alpha = 0 transitionView?.frame = transitionViewFinalFrame transitionView?.center = CGPoint(x: finalFrame.midX, y: finalFrame.midY) - }, completion: {(_) in + }, completion: {[ref = self.referenceImageView] _ in fromViewController.view.alpha = 1 - self.referenceImageView?.alpha = 1 + ref?.alpha = 1 transitionView?.removeFromSuperview() transitionBackgroundView.removeFromSuperview() containerView.addSubview(toViewController.view) diff --git a/ImageSlideshow/Classes/InputSources/AFURLSource.swift b/ImageSlideshow/Classes/InputSources/AFURLSource.swift index c3000ce1..4265174b 100644 --- a/ImageSlideshow/Classes/InputSources/AFURLSource.swift +++ b/ImageSlideshow/Classes/InputSources/AFURLSource.swift @@ -41,8 +41,8 @@ public class AFURLSource: NSObject, InputSource { public func load(to imageView: UIImageView, with callback: @escaping (UIImage?) -> Void) { imageView.setImageWith(URLRequest(url: url), placeholderImage: self.placeholder, success: { (_, _, image: UIImage) in callback(image) - }, failure: { _, _, _ in - callback(self.placeholder) + }, failure: {[placeholder = self.placeholder] _, _, _ in + callback(placeholder) }) } From 28ebd49a52bb1fa9db92ac6cd4e2635d0049fbec Mon Sep 17 00:00:00 2001 From: yoloabdo Date: Tue, 5 Jun 2018 13:49:46 +0200 Subject: [PATCH 2/2] fix relase optionality --- ImageSlideshow/Classes/Core/ImageSlideshowItem.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift b/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift index 984fdbe3..07e3d34f 100644 --- a/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift +++ b/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift @@ -127,7 +127,11 @@ open class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate { activityIndicator?.show() image.load(to: self.imageView) {[weak self] image in // set image to nil if there was a release request during the image load - self?.imageView.image = self?.imageReleased ? nil : image + if let imageRelease = self?.imageReleased, imageRelease { + self?.imageView.image = nil + }else{ + self?.imageView.image = image + } self?.activityIndicator?.hide() self?.loadFailed = image == nil self?.isLoading = false