From 066daa9f00eabb44cb102c6ab21ee7445ea78657 Mon Sep 17 00:00:00 2001 From: Michal Tynior Date: Wed, 2 Nov 2016 14:12:18 +0100 Subject: [PATCH] Add support for Swift 3 --- .swiftlint.yml | 28 ++++ CHANGELOG.md | 6 +- Felucia.xcodeproj/project.pbxproj | 87 ++++++++-- .../xcschemes/Felucia-iOS.xcscheme | 2 +- .../xcschemes/Felucia-tvOS.xcscheme | 2 +- .../xcschemes/Felucia-watchOS.xcscheme | 2 +- FeluciaTests/FeluciaTestsCMYK.swift | 16 +- FeluciaTests/FeluciaTestsHSL.swift | 10 +- FeluciaTests/FeluciaTestsHexColor.swift | 18 +- FeluciaTests/FeluciaTestsRGBAFloat.swift | 4 +- FeluciaTests/FeluciaTestsUtils.swift | 30 ++-- FeluciaTests/Helpers.swift | 6 +- README.md | 58 +++---- Source/Felucia.swift | 158 +++++++++--------- Source/Info-tvOS.plist | 26 --- Source/Info-watchOS.plist | 26 --- Source/{Info-iOS.plist => Info.plist} | 0 17 files changed, 253 insertions(+), 226 deletions(-) create mode 100644 .swiftlint.yml delete mode 100644 Source/Info-tvOS.plist delete mode 100644 Source/Info-watchOS.plist rename Source/{Info-iOS.plist => Info.plist} (100%) diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 0000000..c4bc412 --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,28 @@ +disabled_rules: # rule identifiers to exclude from running +- force_cast +- trailing_whitespace +- control_statement +- type_name +- variable_name +- force_try +# Find all the available rules by running: +# swiftlint rules + +included: # paths to include during linting. `--path` is ignored if present. + + +excluded: # paths to ignore during linting. Takes precedence over `included`. + +# parameterized rules can be customized from this configuration file +line_length: 256 + +function_parameter_count: +- 30 +- 40 + +# parameterized rules are first parameterized as a warning level, then error level. +type_body_length: +- 500 # warning +- 1000 # error + +#reporter: "csv" # reporter type (xcode, json, csv, checkstyle) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73bfdc9..214f59b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,15 @@ # Change Log #### 1.x Releases -- `1.x.x` Releases - [1.x.0](#1xx) +- `1.x.x` Releases - [1.4.0](#140) - `1.3.x` Releases - [1.3.0](#130) - `1.2.x` Releases - [1.2.0](#120) - `1.1.x` Releases - [1.1.0](#110) - `1.0.x` Releases - [1.0.0](#100) --- -## [1.X.X](https://github.com/mtynior/Felucia/releases/tag/1.X.X)# -Released on 2016-XX-XX. +## [1.4.0](https://github.com/mtynior/Felucia/releases/tag/1.4.0) +Released on 2016-11-01. #### Added - Support for Swift Package Manager diff --git a/Felucia.xcodeproj/project.pbxproj b/Felucia.xcodeproj/project.pbxproj index 78d32b3..f0d108c 100644 --- a/Felucia.xcodeproj/project.pbxproj +++ b/Felucia.xcodeproj/project.pbxproj @@ -38,6 +38,11 @@ 900EE6D51CAFF124004AF16A /* Felucia.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Felucia.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 900FFDBA1C0E1B6200B0A2B5 /* Helpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = ""; }; 900FFDBC1C135BCE00B0A2B5 /* FeluciaTestsHSL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeluciaTestsHSL.swift; sourceTree = ""; }; + 901927F91DCA1741000481D7 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; + 901927FE1DCA1A90000481D7 /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = ""; }; + 901927FF1DCA1A90000481D7 /* Felucia.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Felucia.podspec; sourceTree = ""; }; + 901928001DCA1A90000481D7 /* LICENSE.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = LICENSE.md; sourceTree = ""; }; + 901928011DCA1A90000481D7 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 9061C9241BD5602900A191B7 /* Felucia.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Felucia.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9061C92E1BD5602900A191B7 /* FeluciaTests_iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FeluciaTests_iOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 9061C9331BD5602900A191B7 /* FeluciaTestsRGBAInteger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeluciaTestsRGBAInteger.swift; sourceTree = ""; }; @@ -48,9 +53,7 @@ 90A178191C0BB4F30096F9BE /* FeluciaTestsHexColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeluciaTestsHexColor.swift; sourceTree = ""; }; 90F814781D23B22700583FA0 /* Felucia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Felucia.h; sourceTree = ""; }; 90F814791D23B22700583FA0 /* Felucia.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Felucia.swift; sourceTree = ""; }; - 90F8147A1D23B22700583FA0 /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; - 90F8147B1D23B22700583FA0 /* Info-tvOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = ""; }; - 90F8147C1D23B22700583FA0 /* Info-watchOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-watchOS.plist"; sourceTree = ""; }; + 90F8147A1D23B22700583FA0 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 90F814861D23B2DD00583FA0 /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -90,6 +93,11 @@ 9061C91A1BD5602900A191B7 = { isa = PBXGroup; children = ( + 901927FE1DCA1A90000481D7 /* CHANGELOG.md */, + 901927FF1DCA1A90000481D7 /* Felucia.podspec */, + 901928001DCA1A90000481D7 /* LICENSE.md */, + 901928011DCA1A90000481D7 /* README.md */, + 901927F91DCA1741000481D7 /* .swiftlint.yml */, 90F814861D23B2DD00583FA0 /* Package.swift */, 90F814771D23B22700583FA0 /* Source */, 9061C9321BD5602900A191B7 /* FeluciaTests */, @@ -128,9 +136,7 @@ children = ( 90F814781D23B22700583FA0 /* Felucia.h */, 90F814791D23B22700583FA0 /* Felucia.swift */, - 90F8147A1D23B22700583FA0 /* Info-iOS.plist */, - 90F8147B1D23B22700583FA0 /* Info-tvOS.plist */, - 90F8147C1D23B22700583FA0 /* Info-watchOS.plist */, + 90F8147A1D23B22700583FA0 /* Info.plist */, ); path = Source; sourceTree = ""; @@ -173,6 +179,7 @@ 900EE6BF1CAFEFF9004AF16A /* Frameworks */, 900EE6C01CAFEFF9004AF16A /* Headers */, 900EE6C11CAFEFF9004AF16A /* Resources */, + 901927FC1DCA1794000481D7 /* ShellScript */, ); buildRules = ( ); @@ -191,6 +198,7 @@ 900EE6D11CAFF124004AF16A /* Frameworks */, 900EE6D21CAFF124004AF16A /* Headers */, 900EE6D31CAFF124004AF16A /* Resources */, + 901927FD1DCA17A1000481D7 /* ShellScript */, ); buildRules = ( ); @@ -209,6 +217,7 @@ 9061C9201BD5602900A191B7 /* Frameworks */, 9061C9211BD5602900A191B7 /* Headers */, 9061C9221BD5602900A191B7 /* Resources */, + 901927FB1DCA1780000481D7 /* ShellScript */, ); buildRules = ( ); @@ -243,7 +252,7 @@ 9061C91B1BD5602900A191B7 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0810; ORGANIZATIONNAME = "MichaƂ Tynior"; TargetAttributes = { 900EE6C21CAFEFF9004AF16A = { @@ -257,10 +266,12 @@ }; 9061C9231BD5602900A191B7 = { CreatedOnToolsVersion = 7.1; + LastSwiftMigration = 0810; }; 9061C92D1BD5602900A191B7 = { CreatedOnToolsVersion = 7.1; DevelopmentTeam = SGZ6FVQB6B; + LastSwiftMigration = 0810; }; }; }; @@ -315,6 +326,48 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 901927FB1DCA1780000481D7 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + }; + 901927FC1DCA1794000481D7 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + }; + 901927FD1DCA17A1000481D7 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 900EE6BE1CAFEFF9004AF16A /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -375,14 +428,13 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info-watchOS.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tynior.Felucia; PRODUCT_NAME = Felucia; SDKROOT = watchos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -398,7 +450,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info-watchOS.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tynior.Felucia; @@ -406,7 +458,6 @@ SDKROOT = watchos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -421,7 +472,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info-tvOS.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tynior.Felucia; @@ -442,7 +493,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info-tvOS.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tynior.Felucia; @@ -468,8 +519,10 @@ 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_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -497,6 +550,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0.1; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -516,8 +570,10 @@ 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_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -537,6 +593,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_VERSION = 3.0.1; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -553,7 +610,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info-iOS.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tynior.Felucia; @@ -572,7 +629,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info-iOS.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tynior.Felucia; diff --git a/Felucia.xcodeproj/xcshareddata/xcschemes/Felucia-iOS.xcscheme b/Felucia.xcodeproj/xcshareddata/xcschemes/Felucia-iOS.xcscheme index 59063f4..d416b40 100644 --- a/Felucia.xcodeproj/xcshareddata/xcschemes/Felucia-iOS.xcscheme +++ b/Felucia.xcodeproj/xcshareddata/xcschemes/Felucia-iOS.xcscheme @@ -1,6 +1,6 @@ (_ expression1:(T, T, T, T), _ expression2:(T, T, T, T), _ accuracy: T, _ message: String = "", _ file: StaticString = #file, _ line: UInt = #line) { +public func AssertEqualWithAccuracy(_ expression1: (T, T, T, T), _ expression2: (T, T, T, T), _ accuracy: T, _ message: String = "", _ file: StaticString = #file, _ line: UInt = #line) { XCTAssertEqualWithAccuracy(expression1.0, expression2.0, accuracy: accuracy, message, file:file, line:line) XCTAssertEqualWithAccuracy(expression1.1, expression2.1, accuracy: accuracy, message, file:file, line:line) @@ -17,7 +17,7 @@ public func AssertEqualWithAccuracy(_ expression1:(T, T, T, T), XCTAssertEqualWithAccuracy(expression1.3, expression2.3, accuracy: accuracy, message, file:file, line:line) } -public func AssertEqualWithAccuracy(_ expression1:[T], _ expression2:[T], _ accuracy: T, _ message: String = "", _ file: StaticString = #file, _ line: UInt = #line) { +public func AssertEqualWithAccuracy(_ expression1: [T], _ expression2: [T], _ accuracy: T, _ message: String = "", _ file: StaticString = #file, _ line: UInt = #line) { guard expression1.count == expression2.count else { XCTFail(message) @@ -25,6 +25,6 @@ public func AssertEqualWithAccuracy(_ expression1:[T], _ expres } for i in 0.. Bool { +public func == (lhs: UIColor, rhs: UIColor) -> Bool { let lhsRGBA = lhs.rgba() let rhsRGBA = rhs.rgba() @@ -20,7 +20,7 @@ public func ==(lhs:UIColor, rhs:UIColor) -> Bool { && lhsRGBA.a == rhsRGBA.a } -public func !=(lhs:UIColor, rhs:UIColor) -> Bool { +public func != (lhs: UIColor, rhs: UIColor) -> Bool { return !(lhs == rhs) } @@ -28,19 +28,19 @@ public func !=(lhs:UIColor, rhs:UIColor) -> Bool { extension UIColor { - public convenience init(r:Int, g:Int, b:Int, a:Int = 255) { - let ratioRed = Float(UIColor.clamp(r, minValue: 0, maxValue: 255)) / 255.0 - let ratioGreen = Float(UIColor.clamp(g, minValue: 0, maxValue: 255)) / 255.0 - let ratioBlue = Float(UIColor.clamp(b, minValue: 0, maxValue: 255)) / 255.0 - let ratioAlpha = Float(UIColor.clamp(a, minValue: 0, maxValue: 255)) / 255.0 - + public convenience init(r: Int, g: Int, b: Int, a: Int = 255) { + let ratioRed = Float(UIColor.clamp(value: r, minValue: 0, maxValue: 255)) / 255.0 + let ratioGreen = Float(UIColor.clamp(value: g, minValue: 0, maxValue: 255)) / 255.0 + let ratioBlue = Float(UIColor.clamp(value: b, minValue: 0, maxValue: 255)) / 255.0 + let ratioAlpha = Float(UIColor.clamp(value: a, minValue: 0, maxValue: 255)) / 255.0 + self.init(colorLiteralRed: ratioRed, green: ratioGreen, blue: ratioBlue, alpha: ratioAlpha) } - public func rgba() -> (r:Int, g:Int, b:Int, a:Int) { - var fRed : CGFloat = 0 - var fGreen : CGFloat = 0 - var fBlue : CGFloat = 0 + public func rgba() -> (r: Int, g: Int, b: Int, a: Int) { + var fRed: CGFloat = 0 + var fGreen: CGFloat = 0 + var fBlue: CGFloat = 0 var fAlpha: CGFloat = 0 self.getRed(&fRed, green: &fGreen, blue: &fBlue, alpha: &fAlpha) @@ -48,7 +48,7 @@ extension UIColor { let iGreen = Int(round(fGreen * 255.0)) let iBlue = Int(round(fBlue * 255.0)) let iAlpha = Int(round(fAlpha * 255.0)) - + return (iRed, iGreen, iBlue, iAlpha) } @@ -57,44 +57,41 @@ extension UIColor { return [components.r, components.g, components.b, components.a] } - private class func clamp(_ value:Int, minValue:Int, maxValue:Int) -> Int { + private class func clamp(value: Int, minValue: Int, maxValue: Int) -> Int { return max(minValue, min(value, maxValue)) } } -// MARK: - Hex color +// MARK: - Hex color extension UIColor { - public convenience init?(hexARGBString:String) { + public convenience init?(hexARGB: String) { let hex3 = "^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$" let hex6 = "^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$" let hex8 = "^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$" - if let comp = UIColor.getComponents(hexARGBString, pattern: hex3) { + if let comp = UIColor.getComponents(hex: hexARGB, pattern: hex3) { let r = Int(comp[0] + comp[0], radix:16)! let g = Int(comp[1] + comp[1], radix:16)! let b = Int(comp[2] + comp[2], radix:16)! self.init(r:r, g:g, b:b) - } - else if let comp = UIColor.getComponents(hexARGBString, pattern: hex6) { + } else if let comp = UIColor.getComponents(hex: hexARGB, pattern: hex6) { let r = Int(comp[0], radix:16)! let g = Int(comp[1], radix:16)! let b = Int(comp[2], radix:16)! self.init(r:r, g:g, b:b) - } - else if let comp = UIColor.getComponents(hexARGBString, pattern: hex8) { + } else if let comp = UIColor.getComponents(hex: hexARGB, pattern: hex8) { let a = Int(comp[0], radix:16)! let r = Int(comp[1], radix:16)! let g = Int(comp[2], radix:16)! let b = Int(comp[3], radix:16)! self.init(r:r, g:g, b:b, a:a) - - } - else { + + } else { // Failable initializer must set all stored propertied before returning nil :( // In conveniece initializer we have to call designated initializer before returning nil, // otherwise we will get BAD_ACCESS. @@ -103,16 +100,16 @@ extension UIColor { } } - private class func getComponents(_ hexString: String, pattern: String) -> [String]? { - let regex = try! RegularExpression(pattern: pattern, options: .caseInsensitive) + private class func getComponents(hex: String, pattern: String) -> [String]? { + let regex = try! NSRegularExpression(pattern: pattern, options: .caseInsensitive) - guard let match = regex.firstMatch(in: hexString, options:[], range:NSMakeRange(0, hexString.characters.count)) else { + guard let match = regex.firstMatch(in: hex, options: [], range: NSRange(location: 0, length: hex.characters.count)) else { return nil } var components = [String]() for index in 1 ..< match.numberOfRanges { - let component: String = (hexString as NSString).substring(with: match.range(at: index)) + let component: String = (hex as NSString).substring(with: match.rangeAt(index)) components.append(component) } @@ -125,14 +122,14 @@ extension UIColor { extension UIColor { - public convenience init(red: Float, green: Float, blue: Float){ + public convenience init(red: Float, green: Float, blue: Float) { self.init(colorLiteralRed: red, green: green, blue: blue, alpha: 1.0) } - public func rgbaf() -> (r:Float, g:Float, b:Float, a:Float) { - var fRed : CGFloat = 0 - var fGreen : CGFloat = 0 - var fBlue : CGFloat = 0 + public func rgbaf() -> (r: Float, g: Float, b: Float, a: Float) { + var fRed: CGFloat = 0 + var fGreen: CGFloat = 0 + var fBlue: CGFloat = 0 var fAlpha: CGFloat = 0 self.getRed(&fRed, green: &fGreen, blue: &fBlue, alpha: &fAlpha) @@ -150,10 +147,10 @@ extension UIColor { extension UIColor { - public func hsba() -> (h:Float, s:Float, b:Float, a:Float) { - var hue : CGFloat = 0 - var saturation : CGFloat = 0 - var brightness : CGFloat = 0 + public func hsba() -> (h: Float, s: Float, b: Float, a: Float) { + var hue: CGFloat = 0 + var saturation: CGFloat = 0 + var brightness: CGFloat = 0 var alpha: CGFloat = 0 self.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha) @@ -173,64 +170,63 @@ extension UIColor { extension UIColor { - public convenience init(h:Float, s:Float, l:Float, a:Float = 1.0) { - var r:Float - var g:Float - var b:Float + public convenience init(h: Float, s: Float, l: Float, a: Float = 1.0) { + var r: Float + var g: Float + var b: Float let normalizedH = (h > 1) ? (h / 360.0) : h let normalizedS = (s > 1) ? (s / 100.0) : s let normalizedL = (l > 1) ? (l / 100.0) : l - - - if(s == 0){ + + + if(s == 0) { r = l // achromatic g = l b = l - } else{ - let q = (normalizedL < 0.5) ? (normalizedL * (1 + normalizedS)) : (normalizedL + normalizedS - normalizedL * normalizedS); - let p = 2 * normalizedL - q; - r = UIColor.hue2rgb(p, q: q, t1: normalizedH + 1.0/3.0); - g = UIColor.hue2rgb(p, q: q, t1: normalizedH); - b = UIColor.hue2rgb(p, q: q, t1: normalizedH - 1.0/3.0); + } else { + let q = (normalizedL < 0.5) ? (normalizedL * (1 + normalizedS)) : (normalizedL + normalizedS - normalizedL * normalizedS) + let p = 2 * normalizedL - q + r = UIColor.hue2rgb(p: p, q: q, t1: normalizedH + 1.0/3.0) + g = UIColor.hue2rgb(p: p, q: q, t1: normalizedH) + b = UIColor.hue2rgb(p: p, q: q, t1: normalizedH - 1.0/3.0) } - + self.init(colorLiteralRed: r, green: g, blue: b, alpha: a) } - class func hue2rgb(_ p:Float, q:Float, t1:Float) -> Float { + class func hue2rgb(p: Float, q: Float, t1: Float) -> Float { var t = t1 if(t < 0) {t += 1} if(t > 1) {t -= 1} if(t < 1.0/6.0) { return p + (q - p) * 6.0 * t } if(t < 1.0/2.0) { return q } if(t < 2.0/3.0) { return p + (q - p) * (2.0/3.0 - t) * 6.0 } - return p; + return p } - public func hsla() -> (h:Float, s:Float, l:Float, a:Float) { + public func hsla() -> (h: Float, s: Float, l: Float, a: Float) { let components = rgbaf() let minComponent = min(components.r, components.g, components.b) let maxComponent = max(components.r, components.g, components.b) - var h:Float = 0.0 - var s:Float = 0.0 - let l:Float = (minComponent + maxComponent) / 2.0 + var h: Float = 0.0 + var s: Float = 0.0 + let l: Float = (minComponent + maxComponent) / 2.0 if(minComponent == maxComponent) { h = 0.0 s = 0.0 - } - else { + } else { let d: Float = maxComponent - minComponent s = l > 0.5 ? d / Float(2.0 - maxComponent - minComponent) : d / Float((maxComponent + minComponent)) switch(maxComponent) { - case components.r: h = (components.g - components.b) / d + (components.g < components.b ? 6.0 : 0.0) - case components.g: h = (components.b - components.r) / d + 2.0 - case components.b: h = (components.r - components.g) / d + 4.0 - default: h = 0.0 + case components.r: h = (components.g - components.b) / d + (components.g < components.b ? 6.0 : 0.0) + case components.g: h = (components.b - components.r) / d + 2.0 + case components.b: h = (components.r - components.g) / d + 4.0 + default: h = 0.0 } - h /= 6.0; + h /= 6.0 } return (h, s, l, components.a) @@ -247,7 +243,7 @@ extension UIColor { extension UIColor { - public convenience init(cyan: Float, magneta: Float, yellow: Float, black: Float) { + public convenience init(cyan: Float, magneta: Float, yellow: Float, black: Float) { let red = (1 - cyan) * (1 - black) let green = (1 - magneta) * (1 - black) let blue = (1 - yellow) * (1 - black) @@ -256,13 +252,13 @@ extension UIColor { } - public func cmyk() -> (c:Float, m:Float, y:Float, k:Float) { + public func cmyk() -> (c: Float, m: Float, y: Float, k: Float) { let components = rgbaf() let black = 1 - max(components.r, components.g, components.b) let cyan = (1 - components.r - black) / (1 - black) let magneta = (1 - components.g - black) / (1 - black) let yellow = (1 - components.b - black) / (1 - black) - + return (cyan, magneta, yellow, black) } @@ -280,13 +276,13 @@ extension UIColor { let components = rgbaf() return UIColor(red: CGFloat(1.0 - components.r), - green: CGFloat(1.0 - components.g), - blue: CGFloat(1.0 - components.b), - alpha: CGFloat(components.a)) - + green: CGFloat(1.0 - components.g), + blue: CGFloat(1.0 - components.b), + alpha: CGFloat(components.a)) + } - - public func lighten(_ percentage: Float = 0.1) -> UIColor { + + public func lighten(percentage: Float = 0.1) -> UIColor { var components = hsla() components.l += percentage @@ -295,7 +291,7 @@ extension UIColor { return UIColor(h: components.h, s: components.s, l: components.l) } - public func darken(_ percentage: Float = 0.1) -> UIColor { + public func darken(percentage: Float = 0.1) -> UIColor { var components = hsla() components.l -= percentage @@ -309,8 +305,8 @@ extension UIColor { // https://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale var lumaComponent = Float(components.r) * 0.3 - lumaComponent += Float(components.g) * 0.59 - lumaComponent += Float(components.b) * 0.11 + lumaComponent += Float(components.g) * 0.59 + lumaComponent += Float(components.b) * 0.11 let grayComponent = Int(lumaComponent) @@ -324,15 +320,15 @@ extension UIColor { public func isDark() -> Bool { // YIQ equation from http://24ways.org/2010/calculating-color-contrast let components = rgba() - let yiq = (components.r * 299 + components.g * 587 + components.b * 114) / 1000; - return yiq < 128; + let yiq = (components.r * 299 + components.g * 587 + components.b * 114) / 1000 + return yiq < 128 } public class func randomColor() -> UIColor { // Inspired by https://gist.github.com/kylefox/1689973 - let hue : CGFloat = CGFloat(arc4random() % 256) / 256 // use 256 to get full range from 0.0 to 1.0 - let saturation : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from white - let brightness : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from black + let hue: CGFloat = CGFloat(arc4random() % 256) / 256 // use 256 to get full range from 0.0 to 1.0 + let saturation: CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from white + let brightness: CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from black return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: 1) } diff --git a/Source/Info-tvOS.plist b/Source/Info-tvOS.plist deleted file mode 100644 index d3de8ee..0000000 --- a/Source/Info-tvOS.plist +++ /dev/null @@ -1,26 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - $(CURRENT_PROJECT_VERSION) - NSPrincipalClass - - - diff --git a/Source/Info-watchOS.plist b/Source/Info-watchOS.plist deleted file mode 100644 index d3de8ee..0000000 --- a/Source/Info-watchOS.plist +++ /dev/null @@ -1,26 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - $(CURRENT_PROJECT_VERSION) - NSPrincipalClass - - - diff --git a/Source/Info-iOS.plist b/Source/Info.plist similarity index 100% rename from Source/Info-iOS.plist rename to Source/Info.plist