diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 00000000..77b3ba85 --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,44 @@ +opt_in_rules: # some rules are only opt-in + - empty_count + # Find all the available rules by running: + # swiftlint rules +included: # paths to include during linting. `--path` is ignored if present. + - Source +excluded: # paths to ignore during linting. Takes precedence over `included`. + - Carthage + - Pods + +# configurable rules can be customized from this configuration file +# binary rules can set their severity level +force_cast: warning # implicitly +force_try: + severity: warning # explicitly +# rules that have both warning and error levels, can set just the warning level +# implicitly +line_length: 200 +# they can set both implicitly with an array +type_body_length: + - 300 # warning + - 400 # error +# or they can set both explicitly +file_length: + warning: 500 + error: 1200 +# naming rules can set warnings/errors for min_length and max_length +# additionally they can set excluded names +type_name: + min_length: 3 # only warning + max_length: # warning and error + warning: 40 + error: 50 + excluded: iPhone # excluded via string +variable_name: + min_length: # only min_length + error: 2 # only error + excluded: # excluded via string array + - x + - y + - id + - URL + - GlobalAPIKey +reporter: "xcode" # reporter type (xcode, json, csv, checkstyle) diff --git a/Demos/DemoLightbox/.swiftlint.yml b/Demos/DemoLightbox/.swiftlint.yml new file mode 100644 index 00000000..67285aa2 --- /dev/null +++ b/Demos/DemoLightbox/.swiftlint.yml @@ -0,0 +1,44 @@ +opt_in_rules: # some rules are only opt-in + - empty_count + # Find all the available rules by running: + # swiftlint rules +included: # paths to include during linting. `--path` is ignored if present. + - ../../Source +excluded: # paths to ignore during linting. Takes precedence over `included`. + - Carthage + - Pods + +# configurable rules can be customized from this configuration file +# binary rules can set their severity level +force_cast: warning # implicitly +force_try: + severity: warning # explicitly +# rules that have both warning and error levels, can set just the warning level +# implicitly +line_length: 200 +# they can set both implicitly with an array +type_body_length: + - 300 # warning + - 400 # error +# or they can set both explicitly +file_length: + warning: 500 + error: 1200 +# naming rules can set warnings/errors for min_length and max_length +# additionally they can set excluded names +type_name: + min_length: 3 # only warning + max_length: # warning and error + warning: 40 + error: 50 + excluded: iPhone # excluded via string +variable_name: + min_length: # only min_length + error: 2 # only error + excluded: # excluded via string array + - x + - y + - id + - URL + - GlobalAPIKey +reporter: "xcode" # reporter type (xcode, json, csv, checkstyle) diff --git a/Demos/DemoLightbox/DemoLightbox.xcodeproj/project.pbxproj b/Demos/DemoLightbox/DemoLightbox.xcodeproj/project.pbxproj index c5625e35..91d46a2e 100644 --- a/Demos/DemoLightbox/DemoLightbox.xcodeproj/project.pbxproj +++ b/Demos/DemoLightbox/DemoLightbox.xcodeproj/project.pbxproj @@ -11,7 +11,7 @@ 29B4A42F1C43A4320060ED52 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29B4A42E1C43A4320060ED52 /* ViewController.swift */; }; 29B4A4341C43A4320060ED52 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 29B4A4331C43A4320060ED52 /* Assets.xcassets */; }; 29B4A4371C43A4320060ED52 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 29B4A4351C43A4320060ED52 /* LaunchScreen.storyboard */; }; - B7E424F67558A47CB29430AF /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DAE713340DA5D2F2EF13EA8D /* Pods.framework */; }; + 6103C426B512202012223B77 /* Pods_DemoLightbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B292A04CC5B492BBE47FD19B /* Pods_DemoLightbox.framework */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -21,9 +21,10 @@ 29B4A4331C43A4320060ED52 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 29B4A4361C43A4320060ED52 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29B4A4381C43A4320060ED52 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 862984732CE1769B7FCAD107 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; - BF040811A09EF7ED090C748D /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; + 50DA7B1F749AA394FE5653E2 /* Pods-DemoLightbox.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DemoLightbox.release.xcconfig"; path = "Pods/Target Support Files/Pods-DemoLightbox/Pods-DemoLightbox.release.xcconfig"; sourceTree = ""; }; + B292A04CC5B492BBE47FD19B /* Pods_DemoLightbox.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DemoLightbox.framework; sourceTree = BUILT_PRODUCTS_DIR; }; DAE713340DA5D2F2EF13EA8D /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + F6C6211C49ECD8B15F32A93C /* Pods-DemoLightbox.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DemoLightbox.debug.xcconfig"; path = "Pods/Target Support Files/Pods-DemoLightbox/Pods-DemoLightbox.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -31,20 +32,29 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - B7E424F67558A47CB29430AF /* Pods.framework in Frameworks */, + 6103C426B512202012223B77 /* Pods_DemoLightbox.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 153887050C38C94D185F4F31 /* Pods */ = { + isa = PBXGroup; + children = ( + F6C6211C49ECD8B15F32A93C /* Pods-DemoLightbox.debug.xcconfig */, + 50DA7B1F749AA394FE5653E2 /* Pods-DemoLightbox.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; 29B4A4201C43A4320060ED52 = { isa = PBXGroup; children = ( 29B4A42B1C43A4320060ED52 /* DemoLightbox */, 29B4A42A1C43A4320060ED52 /* Products */, - 6D8CFCBA6E48A4A6439CE4EF /* Pods */, B1B2B3DADEEC7FD14D4A9FF8 /* Frameworks */, + 153887050C38C94D185F4F31 /* Pods */, ); sourceTree = ""; }; @@ -68,19 +78,11 @@ path = DemoLightbox; sourceTree = ""; }; - 6D8CFCBA6E48A4A6439CE4EF /* Pods */ = { - isa = PBXGroup; - children = ( - 862984732CE1769B7FCAD107 /* Pods.debug.xcconfig */, - BF040811A09EF7ED090C748D /* Pods.release.xcconfig */, - ); - name = Pods; - sourceTree = ""; - }; B1B2B3DADEEC7FD14D4A9FF8 /* Frameworks */ = { isa = PBXGroup; children = ( DAE713340DA5D2F2EF13EA8D /* Pods.framework */, + B292A04CC5B492BBE47FD19B /* Pods_DemoLightbox.framework */, ); name = Frameworks; sourceTree = ""; @@ -92,12 +94,13 @@ isa = PBXNativeTarget; buildConfigurationList = 29B4A43B1C43A4320060ED52 /* Build configuration list for PBXNativeTarget "DemoLightbox" */; buildPhases = ( - 06282289ACE0FE347CE75481 /* Check Pods Manifest.lock */, + 186F9C312C32802BA8C876A5 /* 📦 Check Pods Manifest.lock */, 29B4A4251C43A4320060ED52 /* Sources */, 29B4A4261C43A4320060ED52 /* Frameworks */, 29B4A4271C43A4320060ED52 /* Resources */, - FE9DC4CBFB4CA271DE44FC3E /* Embed Pods Frameworks */, - D4C01A9FD0D35691D0B9D891 /* Copy Pods Resources */, + 9366497046F222837C2712DC /* 📦 Embed Pods Frameworks */, + 41CDA11DACE14BEC755CB66E /* 📦 Copy Pods Resources */, + BD36DBF51D0584D200BB7175 /* ShellScript */, ); buildRules = ( ); @@ -154,14 +157,14 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 06282289ACE0FE347CE75481 /* Check Pods Manifest.lock */ = { + 186F9C312C32802BA8C876A5 /* 📦 Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Check Pods Manifest.lock"; + name = "📦 Check Pods Manifest.lock"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; @@ -169,36 +172,49 @@ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; - D4C01A9FD0D35691D0B9D891 /* Copy Pods Resources */ = { + 41CDA11DACE14BEC755CB66E /* 📦 Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Copy Pods Resources"; + name = "📦 Copy Pods Resources"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-DemoLightbox/Pods-DemoLightbox-resources.sh\"\n"; showEnvVarsInLog = 0; }; - FE9DC4CBFB4CA271DE44FC3E /* Embed Pods Frameworks */ = { + 9366497046F222837C2712DC /* 📦 Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Embed Pods Frameworks"; + name = "📦 Embed Pods Frameworks"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-frameworks.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-DemoLightbox/Pods-DemoLightbox-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; + BD36DBF51D0584D200BB7175 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + 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 */ @@ -308,7 +324,7 @@ }; 29B4A43C1C43A4320060ED52 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 862984732CE1769B7FCAD107 /* Pods.debug.xcconfig */; + baseConfigurationReference = F6C6211C49ECD8B15F32A93C /* Pods-DemoLightbox.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = DemoLightbox/Info.plist; @@ -320,7 +336,7 @@ }; 29B4A43D1C43A4320060ED52 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = BF040811A09EF7ED090C748D /* Pods.release.xcconfig */; + baseConfigurationReference = 50DA7B1F749AA394FE5653E2 /* Pods-DemoLightbox.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = DemoLightbox/Info.plist; diff --git a/Demos/DemoLightbox/Podfile b/Demos/DemoLightbox/Podfile index 55fefd76..6e41882a 100644 --- a/Demos/DemoLightbox/Podfile +++ b/Demos/DemoLightbox/Podfile @@ -3,6 +3,8 @@ platform :ios, '8.0' use_frameworks! inhibit_all_warnings! +target "DemoLightbox" do pod 'Lightbox', path: '../../' pod 'Sugar' pod 'Hue', git: 'https://github.com/hyperoslo/Hue' +end diff --git a/Demos/DemoLightbox/Podfile.lock b/Demos/DemoLightbox/Podfile.lock index d19ca3f7..d6e73e7c 100644 --- a/Demos/DemoLightbox/Podfile.lock +++ b/Demos/DemoLightbox/Podfile.lock @@ -1,9 +1,9 @@ PODS: - - Hue (1.0.0) + - Hue (1.1) - Lightbox (1.0.0): - Hue - Sugar - - Sugar (1.0.4) + - Sugar (1.1.1) DEPENDENCIES: - Hue (from `https://github.com/hyperoslo/Hue`) @@ -14,16 +14,18 @@ EXTERNAL SOURCES: Hue: :git: https://github.com/hyperoslo/Hue Lightbox: - :path: ../../ + :path: "../../" CHECKOUT OPTIONS: Hue: - :commit: 4f0f8bfdb69d926883216ffe9a802a5a2022f3f5 + :commit: 43404964a799dd0c8affc2d4631ead33df8e04f1 :git: https://github.com/hyperoslo/Hue SPEC CHECKSUMS: - Hue: 44ae8b1091935fcc75055174095ab04653989235 + Hue: c7d6a7206bac669ed69e78cc6c14a4d7bd28277c Lightbox: 857975225b89e83758b4895c035f5621d62e9bba - Sugar: 814a9f59f546b942884a276f32324e73d6f93b11 + Sugar: bed396c924fd089feee7c780778cca2a124f580c -COCOAPODS: 0.39.0 +PODFILE CHECKSUM: 454f6a62854b449796f88a5b1a0617ceb8f8de52 + +COCOAPODS: 1.0.0 diff --git a/Source/Library/LightboxTransition.swift b/Source/Library/LightboxTransition.swift index e2da48bc..b752af5d 100644 --- a/Source/Library/LightboxTransition.swift +++ b/Source/Library/LightboxTransition.swift @@ -22,7 +22,7 @@ class LightboxTransition: UIPercentDrivenInteractiveTransition { } } - var lightboxController: LightboxController? + weak var lightboxController: LightboxController? // MARK: - Transition @@ -79,7 +79,7 @@ class LightboxTransition: UIPercentDrivenInteractiveTransition { self.scrollView?.frame.origin.y = translation.y * 3 controller.view.alpha = 0 controller.view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0) - }, completion: { _ in }) + }, completion: { _ in }) } else { cancelInteractiveTransition() @@ -144,7 +144,9 @@ extension LightboxTransition: UIViewControllerTransitioningDelegate { return self } - func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { + func animationControllerForPresentedController(presented: UIViewController, + presentingController presenting: UIViewController, + sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { dismissing = false return self } diff --git a/Source/LightboxController.swift b/Source/LightboxController.swift index 08eb90ac..9c672bf7 100644 --- a/Source/LightboxController.swift +++ b/Source/LightboxController.swift @@ -67,7 +67,7 @@ public class LightboxController: UIViewController { }() public private(set) lazy var overlayView: UIView = { [unowned self] in - let view = UIView(frame: CGRectZero) + let view = UIView(frame: CGRect.zero) let gradient = CAGradientLayer() let colors = [UIColor.hex("090909").alpha(0), UIColor.hex("040404")] @@ -361,7 +361,7 @@ extension LightboxController: HeaderViewDelegate { } let prevIndex = currentPage - + if currentPage == numberOfPages - 1 { previous() } else { @@ -392,7 +392,7 @@ extension LightboxController: FooterViewDelegate { public func footerView(footerView: FooterView, didExpand expanded: Bool) { footerView.frame.origin.y = screenBounds.height - footerView.frame.height - + UIView.animateWithDuration(0.25) { self.overlayView.alpha = expanded ? 1.0 : 0.0 self.headerView.deleteButton.alpha = expanded ? 0.0 : 1.0 diff --git a/Source/Views/FooterView.swift b/Source/Views/FooterView.swift index 24e03b65..61dc9525 100644 --- a/Source/Views/FooterView.swift +++ b/Source/Views/FooterView.swift @@ -19,7 +19,7 @@ public class FooterView: UIView { }() public private(set) lazy var pageLabel: UILabel = { [unowned self] in - let label = UILabel(frame: CGRectZero) + let label = UILabel(frame: CGRect.zero) label.hidden = !LightboxConfig.PageIndicator.enabled label.numberOfLines = 1 @@ -27,7 +27,7 @@ public class FooterView: UIView { }() public private(set) lazy var separatorView: UIView = { [unowned self] in - let view = UILabel(frame: CGRectZero) + let view = UILabel(frame: CGRect.zero) view.hidden = !LightboxConfig.PageIndicator.enabled view.backgroundColor = LightboxConfig.PageIndicator.separatorColor @@ -40,7 +40,7 @@ public class FooterView: UIView { // MARK: - Initializers public init() { - super.init(frame: CGRectZero) + super.init(frame: CGRect.zero) backgroundColor = UIColor.clearColor() addGradientLayer(gradientColors) @@ -71,7 +71,7 @@ public class FooterView: UIView { if text.isEmpty { removeGradientLayer() - } else if !infoLabel.expanded { + } else if !infoLabel.expanded { addGradientLayer(gradientColors) } } diff --git a/Source/Views/HeaderView.swift b/Source/Views/HeaderView.swift index 5ae333b6..d08b326a 100644 --- a/Source/Views/HeaderView.swift +++ b/Source/Views/HeaderView.swift @@ -60,7 +60,7 @@ public class HeaderView: UIView { // MARK: - Initializers public init() { - super.init(frame: CGRectZero) + super.init(frame: CGRect.zero) backgroundColor = UIColor.clearColor() diff --git a/Source/Views/InfoLabel.swift b/Source/Views/InfoLabel.swift index 3f8b4ac0..c4127b3c 100644 --- a/Source/Views/InfoLabel.swift +++ b/Source/Views/InfoLabel.swift @@ -67,7 +67,7 @@ public class InfoLabel: UILabel { public init(text: String, expanded: Bool = false) { self.fullText = text - super.init(frame: CGRectZero) + super.init(frame: CGRect.zero) numberOfLines = 0 updateText(text) @@ -118,7 +118,7 @@ public class InfoLabel: UILabel { private func heightForString(string: String) -> CGFloat { return string.boundingRectWithSize( - CGSizeMake(bounds.size.width, CGFloat.max), + CGSize(width: bounds.size.width, height: CGFloat.max), options: [.UsesLineFragmentOrigin, .UsesFontLeading], attributes: [NSFontAttributeName : font], context: nil).height diff --git a/Source/Views/PageView.swift b/Source/Views/PageView.swift index d6be8547..14f48509 100644 --- a/Source/Views/PageView.swift +++ b/Source/Views/PageView.swift @@ -18,14 +18,14 @@ class PageView: UIScrollView { }() var image: LightboxImage - var contentFrame = CGRectZero + var contentFrame = CGRect.zero weak var pageViewDelegate: PageViewDelegate? // MARK: - Initializers init(image: LightboxImage) { self.image = image - super.init(frame: CGRectZero) + super.init(frame: CGRect.zero) self.image.addImageTo(imageView) { image in self.userInteractionEnabled = true @@ -71,7 +71,7 @@ class PageView: UIScrollView { let x = pointInView.x - (width / 2.0) let y = pointInView.y - (height / 2.0) - let rectToZoomTo = CGRectMake(x, y, width, height) + let rectToZoomTo = CGRect(x: x, y: y, width: width, height: height) zoomToRect(rectToZoomTo, animated: true) } @@ -95,7 +95,7 @@ class PageView: UIScrollView { height: imageViewSize.height) } - imageView.frame = CGRect(origin: CGPointZero, size: realImageViewSize) + imageView.frame = CGRect(origin: CGPoint.zero, size: realImageViewSize) centerImageView() }