From 789cd94225b74d3369309ac8e103fe27aa3874bf Mon Sep 17 00:00:00 2001 From: Dmitry Rybochkin Date: Tue, 2 Oct 2018 14:02:11 +0300 Subject: [PATCH] adapted for swift 4.2 --- PMHTTP.podspec | 2 +- PMHTTP.xcodeproj/project.pbxproj | 8 ++++---- Sources/PlatformSpecific.swift | 8 ++++---- Tests/ImageTests.swift | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/PMHTTP.podspec b/PMHTTP.podspec index 615dfb9..3d202f2 100644 --- a/PMHTTP.podspec +++ b/PMHTTP.podspec @@ -18,7 +18,7 @@ Pod::Spec.new do |s| s.watchos.deployment_target = "2.0" s.tvos.deployment_target = "9.0" - s.swift_version = '4.0' + s.swift_version = '4.2' s.source = { :git => "https://github.com/postmates/PMHTTP.git", :tag => "v#{s.version}" } s.source_files = "Sources" diff --git a/PMHTTP.xcodeproj/project.pbxproj b/PMHTTP.xcodeproj/project.pbxproj index ccc9293..40f51d7 100644 --- a/PMHTTP.xcodeproj/project.pbxproj +++ b/PMHTTP.xcodeproj/project.pbxproj @@ -589,7 +589,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.postmates.PMHTTP; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -610,7 +610,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.postmates.PMHTTP; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -625,7 +625,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.postmates.PMHTTPTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -639,7 +639,7 @@ "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.postmates.PMHTTPTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Sources/PlatformSpecific.swift b/Sources/PlatformSpecific.swift index 8538ee2..0e362e8 100644 --- a/Sources/PlatformSpecific.swift +++ b/Sources/PlatformSpecific.swift @@ -44,7 +44,7 @@ import Foundation /// - filename: The filename of the attachment. Optional. public func addMultipartPNG(for image: UIImage, withName name: String, filename: String? = nil) { self.addMultipartBody(using: { upload in - guard let data = UIImagePNGRepresentation(image) else { return } + guard let data = image.pngData() else { return } upload.addMultipart(data: data, withName: name, mimeType: "image/png", filename: filename) }) } @@ -69,7 +69,7 @@ import Foundation /// - filename: The filename of the attachment. Optional. public func addMultipartJPEG(for image: UIImage, withCompressionQuality quality: CGFloat, name: String, filename: String? = nil) { self.addMultipartBody(using: { upload in - guard let data = UIImageJPEGRepresentation(image, quality) else { return } + guard let data = image.jpegData(compressionQuality: quality) else { return } upload.addMultipart(data: data, withName: name, mimeType: "image/jpeg", filename: filename) }) } @@ -387,12 +387,12 @@ import Foundation else { return nil } let imageProps = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as NSDictionary? let exifOrientation = (imageProps?[kCGImagePropertyOrientation] as? NSNumber)?.intValue - let orientation = exifOrientation.map(UIImageOrientation.init(exifOrientation:)) ?? .up + let orientation = exifOrientation.map(UIImage.Orientation.init(exifOrientation:)) ?? .up self.init(cgImage: cgImage, scale: scale, orientation: orientation) } } - private extension UIImageOrientation { + private extension UIImage.Orientation { init(exifOrientation orientation: Int) { switch orientation { case 1: self = .up diff --git a/Tests/ImageTests.swift b/Tests/ImageTests.swift index 849dc26..760fb55 100644 --- a/Tests/ImageTests.swift +++ b/Tests/ImageTests.swift @@ -27,7 +27,7 @@ import PMHTTP }() func testGETImage() { - guard let imageData = UIImageJPEGRepresentation(sampleImage, 0.9) else { + guard let imageData = sampleImage.jpegData(compressionQuality: 0.9) else { return XCTFail("Could not get JPEG data for sample image") } expectationForHTTPRequest(httpServer, path: "image") { (request, completion) in @@ -92,7 +92,7 @@ import PMHTTP } func testPOSTImage() { - guard let imageData = UIImageJPEGRepresentation(sampleImage, 0.9) else { + guard let imageData = sampleImage.jpegData(compressionQuality: 0.9) else { return XCTFail("Could not get JPEG data for sample image") } expectationForHTTPRequest(httpServer, path: "image") { (request, completion) in