From 068cd86511e00a24c72c1345c8cca3274a734085 Mon Sep 17 00:00:00 2001 From: Chris Combs Date: Sun, 25 Sep 2016 21:46:16 +0200 Subject: [PATCH 1/3] Updated the APIs to be more swifty --- Codemine/Extensions/CGRect+Utilities.swift | 2 +- Codemine/Extensions/NSURL+AssetSize.swift | 16 +++++++-------- .../Extensions/String+EmailValidation.swift | 2 +- Codemine/Extensions/String+Range.swift | 6 +++--- Codemine/Extensions/UIImage+Utilities.swift | 20 +++++++++---------- Codemine/Extensions/UIView+Utilities.swift | 6 +++--- CodemineTests/CodemineTests.swift | 20 +++++++++---------- CodemineTests/UIImageTests.swift | 6 +++--- CodemineTests/URLImageAssetSizeTests.swift | 8 ++++---- 9 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Codemine/Extensions/CGRect+Utilities.swift b/Codemine/Extensions/CGRect+Utilities.swift index 2367438..6089793 100644 --- a/Codemine/Extensions/CGRect+Utilities.swift +++ b/Codemine/Extensions/CGRect+Utilities.swift @@ -35,7 +35,7 @@ public extension CGRect { - returns: a new CGRect with the width and height reversed to those of the current one */ - public func rectByReversingSize() -> CGRect { + public var reversedSize: CGRect { return CGRect(origin: self.origin, size: CGSize(width: self.height, height: self.width)) } } diff --git a/Codemine/Extensions/NSURL+AssetSize.swift b/Codemine/Extensions/NSURL+AssetSize.swift index 5252caf..4a9323a 100644 --- a/Codemine/Extensions/NSURL+AssetSize.swift +++ b/Codemine/Extensions/NSURL+AssetSize.swift @@ -21,15 +21,15 @@ public extension URL { - Fit: Resizes the image to fit within the width and height boundaries without cropping or distorting the image. The resulting image is assured to match one of the constraining dimensions, while the other dimension is altered to maintain the same aspect ratio of the input image. - - Default: Default/normal image mode. No changes to the ratio. + - Standard: Default/normal image mode. No changes to the ratio. */ public enum ImageUrlMode : String { - case Resize = "resize" - case Crop = "crop" - case Fit = "fit" - case Default = "default" + case resize = "resize" + case crop = "crop" + case fit = "fit" + case standard = "default" } - + /** Adds height, width and mode paramters to an url. To be used when fetching an image from a CDN, for example. Choose the `size` and the `mode` for the image url to define how an image will be provided from the backend. @@ -41,13 +41,13 @@ public extension URL { - widthParameterName: the name of the width paramter. Default is 'h' - Returns: `URL` as a `NSURL`. */ - public func urlByAppendingAssetSize(_ size: CGSize, mode: ImageUrlMode = .Default, heightParameterName : String = "h", widthParameterName : String = "w") -> URL? { + public func appendedAssetSize(_ size: CGSize, mode: ImageUrlMode = .standard, heightParameterName : String = "h", widthParameterName : String = "w") -> URL? { guard var urlComponents = URLComponents(url: self, resolvingAgainstBaseURL: false) else { return nil } var queryItems:[URLQueryItem] = urlComponents.queryItems ?? [] queryItems.append(URLQueryItem(name: widthParameterName, value: "\(Int(size.width * UIScreen.main.scale ))")) queryItems.append(URLQueryItem(name: heightParameterName, value: "\(Int(size.height * UIScreen.main.scale ))")) - if mode != .Default { + if mode != .standard { queryItems.append(URLQueryItem(name: "mode", value: mode.rawValue)) } urlComponents.queryItems = queryItems diff --git a/Codemine/Extensions/String+EmailValidation.swift b/Codemine/Extensions/String+EmailValidation.swift index 5da3dc6..e4bf41e 100644 --- a/Codemine/Extensions/String+EmailValidation.swift +++ b/Codemine/Extensions/String+EmailValidation.swift @@ -16,7 +16,7 @@ public extension String { - returns: true is the current string is a valid email address, false otherwise */ - public func isValidEmailAddress() -> Bool { + public var isValidEmailAddress: Bool { let emailRegex = "\\A[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\\z" let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegex) diff --git a/Codemine/Extensions/String+Range.swift b/Codemine/Extensions/String+Range.swift index 81ecee0..ea6e180 100644 --- a/Codemine/Extensions/String+Range.swift +++ b/Codemine/Extensions/String+Range.swift @@ -17,7 +17,7 @@ public extension String { - returns: true if the string contains that range, false otherwise */ - private func containsRange(_ range: Range) -> Bool { + private func contains(_ range: Range) -> Bool { if range.lowerBound < self.startIndex || range.upperBound > self.endIndex { return false } @@ -42,9 +42,9 @@ public extension String { - returns: the range between the start of the first substring and the end of the last substring */ - public func rangeFromString(_ string: String, toString: String, searchType: RangeSearchType = .leftToRight, inRange: Range? = nil) -> Range? { + public func rangeFrom(string: String, toString: String, searchType: RangeSearchType = .leftToRight, inRange: Range? = nil) -> Range? { let range = inRange ?? Range(uncheckedBounds: (lower: self.startIndex, upper: self.endIndex)) - if !containsRange(range) { return nil } + if !contains(range) { return nil } guard let firstRange = self.range(of: string, options: NSString.CompareOptions(rawValue: 0), range: range, locale: nil) else { return nil } guard let secondRange = self.range(of: toString, options: NSString.CompareOptions(rawValue: 0), range: range, locale: nil) else { return nil } diff --git a/Codemine/Extensions/UIImage+Utilities.swift b/Codemine/Extensions/UIImage+Utilities.swift index 6cf38bb..61e9760 100644 --- a/Codemine/Extensions/UIImage+Utilities.swift +++ b/Codemine/Extensions/UIImage+Utilities.swift @@ -24,7 +24,7 @@ public extension UIImage { - Returns: A 'UIImage' with the specified color, size and corner radius. */ - public class func imageFromColor(_ color: UIColor, size: CGSize, cornerRadius: CGFloat) -> UIImage? { + public class func from(color: UIColor, size: CGSize, cornerRadius: CGFloat) -> UIImage? { /// The base rectangle of the image. let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) @@ -53,22 +53,22 @@ public extension UIImage { /** Embed an icon/image on top of a background image. - `imageOne` will be the background and `icon` is the image that will be on top of `imageOne`. - The `UIImage` that is set with the parameter `icon` will be centered on `imageOne`. + `image` will be the background and `icon` is the image that will be on top of `image`. + The `UIImage` that is set with the parameter `icon` will be centered on `image`. - Parameters: - - imageOne: The background image. - - icon: The embedded image that will be on top. + - icon: The embedded image that will be on top. + - image: The background image. - Returns: The combined image as `UIImage`. */ - public class func imageByEmbeddingIconIn(_ imageOne: UIImage, icon: UIImage) -> UIImage? { - let newSize = CGSize(width: imageOne.size.width, height: imageOne.size.height) + public class func embed(icon: UIImage, inImage image: UIImage ) -> UIImage? { + let newSize = CGSize(width: image.size.width, height: image.size.height) UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0) - imageOne.draw(in: CGRect(x: 0,y: 0,width: newSize.width,height: newSize.height)) + image.draw(in: CGRect(x: 0,y: 0,width: newSize.width,height: newSize.height)) // Center icon - icon.draw(in: CGRect(x: imageOne.size.width/2 - icon.size.width/2, y: imageOne.size.height/2 - icon.size.height/2, width: icon.size.width, height: icon.size.height), blendMode:CGBlendMode.normal, alpha:1.0) + icon.draw(in: CGRect(x: image.size.width/2 - icon.size.width/2, y: image.size.height/2 - icon.size.height/2, width: icon.size.width, height: icon.size.height), blendMode:CGBlendMode.normal, alpha:1.0) let newImage = UIGraphicsGetImageFromCurrentImageContext() return newImage @@ -80,7 +80,7 @@ public extension UIImage { - Returns: The orientation corrected image as an `UIImage`. */ - public func rotationCorrectedImage() -> UIImage? { + public var rotationCorrected: UIImage? { // if (self.imageOrientation == UIImageOrientation.Up) { return self } UIGraphicsBeginImageContextWithOptions(self.size, false, self.scale) diff --git a/Codemine/Extensions/UIView+Utilities.swift b/Codemine/Extensions/UIView+Utilities.swift index 8361843..cc286dd 100644 --- a/Codemine/Extensions/UIView+Utilities.swift +++ b/Codemine/Extensions/UIView+Utilities.swift @@ -14,11 +14,11 @@ public extension UIView { Assign a `nibName` to a UIView. Later on you can call this `UIView` by its `nibName`. - - Parameter nibName: The name that the UIView will get as its `nibName` assigned as a `String`. + - Parameter name: The name that the UIView will get as its `name` assigned as a `String`. - Returns: `Generics type`. */ - public static func viewWithNibNamed(_ nibName:String) -> T? { - let view = UINib(nibName: nibName, bundle: nil).instantiate(withOwner: nil, options: nil).first as? T + public static func fromNib(_ name:String) -> T? { + let view = UINib(nibName: name, bundle: nil).instantiate(withOwner: nil, options: nil).first as? T return view } diff --git a/CodemineTests/CodemineTests.swift b/CodemineTests/CodemineTests.swift index 02a8fc3..b7b3d8a 100644 --- a/CodemineTests/CodemineTests.swift +++ b/CodemineTests/CodemineTests.swift @@ -38,29 +38,29 @@ class CodemineTests: XCTestCase { func testTrueEmailAddress() { let validEmails = ["TeSt@TesT.COM", "Test@test.com", "email@example.com", "firstname.lastname@example.com", "email@subdomain.example.com", "firstname+lastname@example.com", "1234567890@example.com", "email@example-one.com", "_______@example.com", "email@example.name", "email@example.museum", "email@example.co.jp", "firstname-lastname@example.com"] for emailAddress in validEmails { - XCTAssertTrue(emailAddress.isValidEmailAddress(), "the email address: \(emailAddress) was considered invalid, but it is not") + XCTAssertTrue(emailAddress.isValidEmailAddress, "the email address: \(emailAddress) was considered invalid, but it is not") } } func testFalseEmailAddress() { let invalidEmails = ["plainaddress", "#@%^%#$@#$@#.com", "@example.com", "Joe Smith ", "email.example.com", "email@example@example.com", ".email@example.com", "email.@example.com", "email..email@example.com", "あいうえお@example.com", "email@example.com (Joe Smith)", "email@example", "email@-example.com", "email@example..com", "Abc..123@example.com"] for emailAddress in invalidEmails { - XCTAssertFalse(emailAddress.isValidEmailAddress(), "the email address: \(emailAddress) was considered valid, but it is not") + XCTAssertFalse(emailAddress.isValidEmailAddress, "the email address: \(emailAddress) was considered valid, but it is not") } } func testRange() { let str = "Hello world!" - let range = str.rangeFromString("e", toString: " w") + let range = str.rangeFrom(string: "e", toString: " w") XCTAssertTrue(range?.lowerBound == str.characters.index(str.startIndex, offsetBy: 1) && range?.upperBound == str.characters.index(str.startIndex, offsetBy: 7), "range = \(range)") - XCTAssertNil(str.rangeFromString("a", toString: "e")) - XCTAssertNil(str.rangeFromString("e", toString: "b")) - - XCTAssertNil(str.rangeFromString("l", toString: "o", searchType: .rightToLeft, inRange: range)) + XCTAssertNil(str.rangeFrom(string: "a", toString: "e")) + XCTAssertNil(str.rangeFrom(string: "e", toString: "b")) + + XCTAssertNil(str.rangeFrom(string: "l", toString: "o", searchType: .rightToLeft, inRange: range)) let str2 = "abcdefghijklmnopqrstuvwxyz" - let range2 = str2.rangeFromString("x", toString: "z") - XCTAssertNil(str.rangeFromString("h", toString: "e", searchType: .leftToRight, inRange: range2)) + let range2 = str2.rangeFrom(string: "x", toString: "z") + XCTAssertNil(str.rangeFrom(string: "h", toString: "e", searchType: .leftToRight, inRange: range2)) } @@ -96,7 +96,7 @@ class CodemineTests: XCTestCase { func testReversingSize() { let rect = CGRect(x: 10, y: 10, width: 100, height: 200) - let reversedRect = rect.rectByReversingSize() + let reversedRect = rect.reversedSize XCTAssertTrue(rect.size.height == reversedRect.size.width && rect.size.width == reversedRect.size.height) } diff --git a/CodemineTests/UIImageTests.swift b/CodemineTests/UIImageTests.swift index f8ab579..251ed77 100644 --- a/CodemineTests/UIImageTests.swift +++ b/CodemineTests/UIImageTests.swift @@ -23,15 +23,15 @@ class UIImageTests: XCTestCase { } func testUIImageFromColor() { - XCTAssertNotNil(UIImage.imageFromColor(.red, size: CGSize(width: 20, height: 20), cornerRadius: 1.0), "Failed to convert color to image") + XCTAssertNotNil(UIImage.from(color: .red, size: CGSize(width: 20, height: 20), cornerRadius: 1.0), "Failed to convert color to image") } func testImageImbed() { - XCTAssertNotNil(UIImage.imageByEmbeddingIconIn(testImageNamed(name: "add"), icon: testImageNamed(name: "alert")), "Failed to embed image") + XCTAssertNotNil(UIImage.embed(icon: testImageNamed(name: "alert"), inImage: testImageNamed(name: "add")), "Failed to embed image") } func testImageRotation() { - XCTAssertNotNil(testImageNamed(name: "add").rotationCorrectedImage(), "Failed to rotate image") + XCTAssertNotNil(testImageNamed(name: "add").rotationCorrected, "Failed to rotate image") } } diff --git a/CodemineTests/URLImageAssetSizeTests.swift b/CodemineTests/URLImageAssetSizeTests.swift index 057c5f5..2f15d24 100644 --- a/CodemineTests/URLImageAssetSizeTests.swift +++ b/CodemineTests/URLImageAssetSizeTests.swift @@ -23,13 +23,13 @@ class URLImageAssetSizeTests: XCTestCase { let heightParameterName = "height" let widthParameterName = "width" - let url2 = url.urlByAppendingAssetSize(size, mode: .Default, heightParameterName: heightParameterName, widthParameterName: widthParameterName) + let url2 = url.appendedAssetSize(size, mode: .standard, heightParameterName: heightParameterName, widthParameterName: widthParameterName) XCTAssertEqual(url2?.absoluteString, url.absoluteString + "?\(widthParameterName)=\(Int(size.width * UIScreen.main.scale ))&\(heightParameterName)=\(Int(size.height * UIScreen.main.scale))") - let url3 = url.urlByAppendingAssetSize(size) + let url3 = url.appendedAssetSize(size) XCTAssertEqual(url3?.absoluteString, url.absoluteString + "?w=\(Int(size.width * UIScreen.main.scale ))&h=\(Int(size.height * UIScreen.main.scale))") - let url4 = url.urlByAppendingAssetSize(size, mode: .Crop) + let url4 = url.appendedAssetSize(size, mode: .crop) XCTAssertEqual(url4?.absoluteString, url.absoluteString + "?w=\(Int(size.width * UIScreen.main.scale ))&h=\(Int(size.height * UIScreen.main.scale))&mode=crop") } @@ -39,7 +39,7 @@ class URLImageAssetSizeTests: XCTestCase { print(URLComponents(url: url, resolvingAgainstBaseURL: false)) - let newUrl = url.urlByAppendingAssetSize(CGSize(width: 10, height: 10)) + let newUrl = url.appendedAssetSize(CGSize(width: 10, height: 10)) XCTAssertNil(newUrl?.absoluteString, "Bad URL did not return nil") } From 203137e5d83fd3390a92c0f35ae5b9c9a10e06fc Mon Sep 17 00:00:00 2001 From: Marius Constantinescu Date: Wed, 21 Dec 2016 15:59:54 +0100 Subject: [PATCH 2/3] A bit more renaming --- Codemine/Extensions/CGRect+Utilities.swift | 2 +- Codemine/Extensions/String+Range.swift | 4 ++-- Codemine/Extensions/UIImage+Utilities.swift | 6 ++++-- Codemine/Extensions/UIView+Utilities.swift | 4 ++-- CodemineTests/CodemineTests.swift | 14 +++++++------- CodemineTests/UIImageTests.swift | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Codemine/Extensions/CGRect+Utilities.swift b/Codemine/Extensions/CGRect+Utilities.swift index 6089793..d40deb8 100644 --- a/Codemine/Extensions/CGRect+Utilities.swift +++ b/Codemine/Extensions/CGRect+Utilities.swift @@ -35,7 +35,7 @@ public extension CGRect { - returns: a new CGRect with the width and height reversed to those of the current one */ - public var reversedSize: CGRect { + public var reversingSize: CGRect { return CGRect(origin: self.origin, size: CGSize(width: self.height, height: self.width)) } } diff --git a/Codemine/Extensions/String+Range.swift b/Codemine/Extensions/String+Range.swift index ea6e180..bdb31b1 100644 --- a/Codemine/Extensions/String+Range.swift +++ b/Codemine/Extensions/String+Range.swift @@ -42,11 +42,11 @@ public extension String { - returns: the range between the start of the first substring and the end of the last substring */ - public func rangeFrom(string: String, toString: String, searchType: RangeSearchType = .leftToRight, inRange: Range? = nil) -> Range? { + public func range(from fromString: String, toString: String, searchType: RangeSearchType = .leftToRight, inRange: Range? = nil) -> Range? { let range = inRange ?? Range(uncheckedBounds: (lower: self.startIndex, upper: self.endIndex)) if !contains(range) { return nil } - guard let firstRange = self.range(of: string, options: NSString.CompareOptions(rawValue: 0), range: range, locale: nil) else { return nil } + guard let firstRange = self.range(of: fromString, options: NSString.CompareOptions(rawValue: 0), range: range, locale: nil) else { return nil } guard let secondRange = self.range(of: toString, options: NSString.CompareOptions(rawValue: 0), range: range, locale: nil) else { return nil } switch searchType { diff --git a/Codemine/Extensions/UIImage+Utilities.swift b/Codemine/Extensions/UIImage+Utilities.swift index 61e9760..7a545dd 100644 --- a/Codemine/Extensions/UIImage+Utilities.swift +++ b/Codemine/Extensions/UIImage+Utilities.swift @@ -24,7 +24,9 @@ public extension UIImage { - Returns: A 'UIImage' with the specified color, size and corner radius. */ - public class func from(color: UIColor, size: CGSize, cornerRadius: CGFloat) -> UIImage? { + + convenience init(color: UIColor, size: CGSize, cornerRadius: CGFloat) { + self.init() /// The base rectangle of the image. let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) @@ -47,9 +49,9 @@ public extension UIImage { image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() - return image } + /** Embed an icon/image on top of a background image. diff --git a/Codemine/Extensions/UIView+Utilities.swift b/Codemine/Extensions/UIView+Utilities.swift index cc286dd..3aeda2e 100644 --- a/Codemine/Extensions/UIView+Utilities.swift +++ b/Codemine/Extensions/UIView+Utilities.swift @@ -17,8 +17,8 @@ public extension UIView { - Parameter name: The name that the UIView will get as its `name` assigned as a `String`. - Returns: `Generics type`. */ - public static func fromNib(_ name:String) -> T? { - let view = UINib(nibName: name, bundle: nil).instantiate(withOwner: nil, options: nil).first as? T + public static func from(nibWithName:String) -> T? { + let view = UINib(nibName: nibWithName, bundle: nil).instantiate(withOwner: nil, options: nil).first as? T return view } diff --git a/CodemineTests/CodemineTests.swift b/CodemineTests/CodemineTests.swift index b7b3d8a..175dcbc 100644 --- a/CodemineTests/CodemineTests.swift +++ b/CodemineTests/CodemineTests.swift @@ -51,16 +51,16 @@ class CodemineTests: XCTestCase { func testRange() { let str = "Hello world!" - let range = str.rangeFrom(string: "e", toString: " w") + let range = str.range(from: "e", toString: " w") XCTAssertTrue(range?.lowerBound == str.characters.index(str.startIndex, offsetBy: 1) && range?.upperBound == str.characters.index(str.startIndex, offsetBy: 7), "range = \(range)") - XCTAssertNil(str.rangeFrom(string: "a", toString: "e")) - XCTAssertNil(str.rangeFrom(string: "e", toString: "b")) + XCTAssertNil(str.range(from: "a", toString: "e")) + XCTAssertNil(str.range(from: "e", toString: "b")) - XCTAssertNil(str.rangeFrom(string: "l", toString: "o", searchType: .rightToLeft, inRange: range)) + XCTAssertNil(str.range(from: "l", toString: "o", searchType: .rightToLeft, inRange: range)) let str2 = "abcdefghijklmnopqrstuvwxyz" - let range2 = str2.rangeFrom(string: "x", toString: "z") - XCTAssertNil(str.rangeFrom(string: "h", toString: "e", searchType: .leftToRight, inRange: range2)) + let range2 = str2.range(from: "x", toString: "z") + XCTAssertNil(str.range(from: "h", toString: "e", searchType: .leftToRight, inRange: range2)) } @@ -96,7 +96,7 @@ class CodemineTests: XCTestCase { func testReversingSize() { let rect = CGRect(x: 10, y: 10, width: 100, height: 200) - let reversedRect = rect.reversedSize + let reversedRect = rect.reversingSize XCTAssertTrue(rect.size.height == reversedRect.size.width && rect.size.width == reversedRect.size.height) } diff --git a/CodemineTests/UIImageTests.swift b/CodemineTests/UIImageTests.swift index 251ed77..be4ea93 100644 --- a/CodemineTests/UIImageTests.swift +++ b/CodemineTests/UIImageTests.swift @@ -23,7 +23,7 @@ class UIImageTests: XCTestCase { } func testUIImageFromColor() { - XCTAssertNotNil(UIImage.from(color: .red, size: CGSize(width: 20, height: 20), cornerRadius: 1.0), "Failed to convert color to image") + XCTAssertNotNil(UIImage(color: .red, size: CGSize(width: 20, height: 20), cornerRadius: 1.0), "Failed to convert color to image") } func testImageImbed() { From ed9714670949984a292048a5d0adbcac3798c16e Mon Sep 17 00:00:00 2001 From: Marius Constantinescu Date: Wed, 21 Dec 2016 16:30:00 +0100 Subject: [PATCH 3/3] More renaming --- Codemine/Extensions/CGRect+Utilities.swift | 2 +- Codemine/Extensions/NSURL+AssetSize.swift | 6 +++--- Codemine/Extensions/UIImage+Utilities.swift | 1 - CodemineTests/URLImageAssetSizeTests.swift | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Codemine/Extensions/CGRect+Utilities.swift b/Codemine/Extensions/CGRect+Utilities.swift index d40deb8..8c11a92 100644 --- a/Codemine/Extensions/CGRect+Utilities.swift +++ b/Codemine/Extensions/CGRect+Utilities.swift @@ -36,6 +36,6 @@ public extension CGRect { - returns: a new CGRect with the width and height reversed to those of the current one */ public var reversingSize: CGRect { - return CGRect(origin: self.origin, size: CGSize(width: self.height, height: self.width)) + return CGRect(origin: origin, size: CGSize(width: height, height: width)) } } diff --git a/Codemine/Extensions/NSURL+AssetSize.swift b/Codemine/Extensions/NSURL+AssetSize.swift index 4a9323a..ded1ccf 100644 --- a/Codemine/Extensions/NSURL+AssetSize.swift +++ b/Codemine/Extensions/NSURL+AssetSize.swift @@ -27,7 +27,7 @@ public extension URL { case resize = "resize" case crop = "crop" case fit = "fit" - case standard = "default" + case `default` = "default" } /** @@ -41,13 +41,13 @@ public extension URL { - widthParameterName: the name of the width paramter. Default is 'h' - Returns: `URL` as a `NSURL`. */ - public func appendedAssetSize(_ size: CGSize, mode: ImageUrlMode = .standard, heightParameterName : String = "h", widthParameterName : String = "w") -> URL? { + public func appendedAssetSize(_ size: CGSize, mode: ImageUrlMode = .default, heightParameterName : String = "h", widthParameterName : String = "w") -> URL? { guard var urlComponents = URLComponents(url: self, resolvingAgainstBaseURL: false) else { return nil } var queryItems:[URLQueryItem] = urlComponents.queryItems ?? [] queryItems.append(URLQueryItem(name: widthParameterName, value: "\(Int(size.width * UIScreen.main.scale ))")) queryItems.append(URLQueryItem(name: heightParameterName, value: "\(Int(size.height * UIScreen.main.scale ))")) - if mode != .standard { + if mode != .default { queryItems.append(URLQueryItem(name: "mode", value: mode.rawValue)) } urlComponents.queryItems = queryItems diff --git a/Codemine/Extensions/UIImage+Utilities.swift b/Codemine/Extensions/UIImage+Utilities.swift index 7a545dd..90b6a57 100644 --- a/Codemine/Extensions/UIImage+Utilities.swift +++ b/Codemine/Extensions/UIImage+Utilities.swift @@ -83,7 +83,6 @@ public extension UIImage { - Returns: The orientation corrected image as an `UIImage`. */ public var rotationCorrected: UIImage? { - // if (self.imageOrientation == UIImageOrientation.Up) { return self } UIGraphicsBeginImageContextWithOptions(self.size, false, self.scale) self.draw(in: CGRect(origin: CGPoint.zero, size: self.size)) diff --git a/CodemineTests/URLImageAssetSizeTests.swift b/CodemineTests/URLImageAssetSizeTests.swift index 2f15d24..d2cccaa 100644 --- a/CodemineTests/URLImageAssetSizeTests.swift +++ b/CodemineTests/URLImageAssetSizeTests.swift @@ -23,7 +23,7 @@ class URLImageAssetSizeTests: XCTestCase { let heightParameterName = "height" let widthParameterName = "width" - let url2 = url.appendedAssetSize(size, mode: .standard, heightParameterName: heightParameterName, widthParameterName: widthParameterName) + let url2 = url.appendedAssetSize(size, mode: .default, heightParameterName: heightParameterName, widthParameterName: widthParameterName) XCTAssertEqual(url2?.absoluteString, url.absoluteString + "?\(widthParameterName)=\(Int(size.width * UIScreen.main.scale ))&\(heightParameterName)=\(Int(size.height * UIScreen.main.scale))") let url3 = url.appendedAssetSize(size)