Skip to content

Commit

Permalink
Add Additional Image MIME Types, Dynamic Per OS (#434)
Browse files Browse the repository at this point in the history
* Update project for Xcode 12.

* Fix Carthage usage.

* Update formatting.

* Make default MIME types dynamic for OS versions.

* Update GitHub CI.

* Update iOS tests, formatting.

* Disable WebP on tvOS.

* Add newline.

* Fix test for lower os versions.

* Conditionalize WebP test.

* Use Big Sur for macOS tests.

* Guard at runtime.

* Remove unnecessary availability.

* Update to Xcode 12.4.

* Update CI to 12.4.

* Fix tvOS version.

* Remove unnecessary guard.
  • Loading branch information
jshier committed Apr 3, 2021
1 parent e6818db commit e9a13dd
Show file tree
Hide file tree
Showing 26 changed files with 344 additions and 202 deletions.
46 changes: 29 additions & 17 deletions .github/workflows/ci.yml
Expand Up @@ -11,28 +11,40 @@ on:

jobs:
macOS_5_1:
name: Test macOS (5.1)
name: Build macOS (5.1)
runs-on: macOS-latest
env:
DEVELOPER_DIR: /Applications/Xcode_11.3.1.app/Contents/Developer
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Dependencies
run: carthage bootstrap --no-use-binaries --platform macOS
- name: macOS
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace "AlamofireImage.xcworkspace" -scheme "AlamofireImage macOS" -destination "platform=macOS" clean test | xcpretty
run: ./carthage.sh bootstrap --no-use-binaries --platform macOS
- name: macOS (5.1)
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace "AlamofireImage.xcworkspace" -scheme "AlamofireImage macOS" -destination "platform=macOS" clean build | xcpretty
macOS_5_2:
name: Test macOS (5.2)
runs-on: macOS-latest
env:
DEVELOPER_DIR: /Applications/Xcode_11.6.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_11.7.app/Contents/Developer
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Dependencies
run: ./carthage.sh bootstrap --no-use-binaries --platform macOS
- name: macOS (5.2)
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace "AlamofireImage.xcworkspace" -scheme "AlamofireImage macOS" -destination "platform=macOS" clean test | xcpretty
macOS_5_3:
name: Test macOS (5.3)
runs-on: macOS-latest
env:
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Dependencies
run: carthage bootstrap --no-use-binaries --platform macOS
- name: macOS
run: ./carthage.sh bootstrap --no-use-binaries --platform macOS
- name: macOS (5.3)
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace "AlamofireImage.xcworkspace" -scheme "AlamofireImage macOS" -destination "platform=macOS" clean test | xcpretty
# Catalyst:
# name: Test Catalyst
Expand All @@ -49,52 +61,52 @@ jobs:
name: Test iOS
runs-on: macOS-latest
env:
DEVELOPER_DIR: /Applications/Xcode_11.6.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
strategy:
matrix:
destination: ["OS=13.6,name=iPhone 11 Pro"]
destination: ["OS=14.4,name=iPhone 12 Pro"]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Dependencies
run: carthage bootstrap --no-use-binaries --platform iOS
run: ./carthage.sh bootstrap --no-use-binaries --platform iOS
- name: iOS - ${{ matrix.destination }}
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace "AlamofireImage.xcworkspace" -scheme "AlamofireImage iOS" -destination "${{ matrix.destination }}" clean test | xcpretty
tvOS:
name: Test tvOS
runs-on: macOS-latest
env:
DEVELOPER_DIR: /Applications/Xcode_11.6.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
strategy:
matrix:
destination: ["OS=13.4,name=Apple TV 4K"]
destination: ["OS=14.3,name=Apple TV 4K"]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Dependencies
run: carthage bootstrap --no-use-binaries --platform tvOS
run: ./carthage.sh bootstrap --no-use-binaries --platform tvOS
- name: tvOS - ${{ matrix.destination }}
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace "AlamofireImage.xcworkspace" -scheme "AlamofireImage tvOS" -destination "${{ matrix.destination }}" clean test | xcpretty
watchOS:
name: Build watchOS
runs-on: macOS-latest
env:
DEVELOPER_DIR: /Applications/Xcode_11.6.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
strategy:
matrix:
destination: ["OS=6.2.1,name=Apple Watch Series 5 - 44mm"]
destination: ["OS=7.2,name=Apple Watch Series 6 - 44mm"]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Dependencies
run: carthage bootstrap --no-use-binaries --platform watchOS
run: ./carthage.sh bootstrap --no-use-binaries --platform watchOS
- name: watchOS - ${{ matrix.destination }}
run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace "AlamofireImage.xcworkspace" -scheme "AlamofireImage watchOS" -destination "${{ matrix.destination }}" clean build | xcpretty
spm:
name: Build with SPM
runs-on: macOS-latest
env:
DEVELOPER_DIR: /Applications/Xcode_11.6.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_12.4.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- name: SPM Build
Expand Down
2 changes: 2 additions & 0 deletions .swiftformat
Expand Up @@ -6,6 +6,7 @@
# rules
--enable isEmpty
--disable andOperator
--disable wrapMultilineStatementBraces

# format options

Expand All @@ -15,6 +16,7 @@
--decimalgrouping 3,5
--exponentcase lowercase
--exponentgrouping disabled
--extensionacl on-declarations
--fractiongrouping disabled
--ifdef no-indent
--importgrouping testable-top
Expand Down
4 changes: 3 additions & 1 deletion AlamofireImage.xcodeproj/project.pbxproj
Expand Up @@ -1479,7 +1479,7 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 1000;
LastUpgradeCheck = 1140;
LastUpgradeCheck = 1240;
ORGANIZATIONNAME = Alamofire;
TargetAttributes = {
4C11830A2150517E007A8298 = {
Expand Down Expand Up @@ -2378,6 +2378,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -2445,6 +2446,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
@@ -1 +1 @@
github "Alamofire/Alamofire" ~> 5.1.0
github "Alamofire/Alamofire" ~> 5.4.0
2 changes: 1 addition & 1 deletion Cartfile.resolved
@@ -1 +1 @@
github "Alamofire/Alamofire" "5.1.0"
github "Alamofire/Alamofire" "5.4.1"
4 changes: 2 additions & 2 deletions Example/Source/Gravatar.swift
Expand Up @@ -25,8 +25,8 @@
import Foundation
import UIKit

private extension String {
var md5Hash: String {
extension String {
fileprivate var md5Hash: String {
let trimmedString = lowercased().trimmingCharacters(in: .whitespaces)
let utf8String = trimmedString.cString(using: .utf8)!
let stringLength = CC_LONG(trimmedString.lengthOfBytes(using: .utf8))
Expand Down
1 change: 1 addition & 0 deletions Example/Source/ImageCell.swift
Expand Up @@ -51,6 +51,7 @@ class ImageCell: UICollectionViewCell {
imageView.frame = contentView.bounds
}

@available(*, unavailable)
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Expand Up @@ -32,7 +32,7 @@ let package = Package(name: "AlamofireImage",
.watchOS(.v3)],
products: [.library(name: "AlamofireImage", targets: ["AlamofireImage"])],
dependencies: [.package(url: "https://github.com/Alamofire/Alamofire.git",
from: "5.1.0")],
from: "5.4.0")],
targets: [.target(name: "AlamofireImage",
dependencies: ["Alamofire"],
path: "Source")],
Expand Down
2 changes: 1 addition & 1 deletion Source/ImageDownloader.swift
Expand Up @@ -399,7 +399,7 @@ open class ImageDownloader {
DispatchQueue.main.async { completion?(response.mapError { AFIError.alamofireError($0) }) }
}
}
})
})

// 4) Store the response handler for use when the request completes
let responseHandler = ResponseHandler(request: request,
Expand Down
15 changes: 6 additions & 9 deletions Source/ImageFilter.swift
Expand Up @@ -110,14 +110,14 @@ public protocol CompositeImageFilter: ImageFilter {
var filters: [ImageFilter] { get }
}

public extension CompositeImageFilter {
extension CompositeImageFilter {
/// The unique idenitifier for any `CompositeImageFilter` type.
var identifier: String {
public var identifier: String {
filters.map { $0.identifier }.joined(separator: "_")
}

/// The filter closure for any `CompositeImageFilter` type.
var filter: (Image) -> Image {
public var filter: (Image) -> Image {
{ image in
self.filters.reduce(image) { $1.filter($0) }
}
Expand Down Expand Up @@ -287,7 +287,6 @@ public struct CircleFilter: ImageFilter {
#if os(iOS) || os(tvOS)

/// The `CoreImageFilter` protocol defines `parameters`, `filterName` properties used by CoreImage.
@available(iOS 9.0, *)
public protocol CoreImageFilter: ImageFilter {
/// The filter name of the CoreImage filter.
var filterName: String { get }
Expand All @@ -296,21 +295,19 @@ public protocol CoreImageFilter: ImageFilter {
var parameters: [String: Any] { get }
}

@available(iOS 9.0, *)
public extension ImageFilter where Self: CoreImageFilter {
extension ImageFilter where Self: CoreImageFilter {
/// The filter closure used to create the modified representation of the given image.
var filter: (Image) -> Image {
public var filter: (Image) -> Image {
{ image in
image.af.imageFiltered(withCoreImageFilter: self.filterName, parameters: self.parameters) ?? image
}
}

/// The unique idenitifier for an `ImageFilter` conforming to the `CoreImageFilter` protocol.
var identifier: String { "\(type(of: self))-parameters:(\(parameters))" }
public var identifier: String { "\(type(of: self))-parameters:(\(parameters))" }
}

/// Blurs an image using a `CIGaussianBlur` filter with the specified blur radius.
@available(iOS 9.0, *)
public struct BlurFilter: ImageFilter, CoreImageFilter {
/// The filter name.
public let filterName = "CIGaussianBlur"
Expand Down
41 changes: 28 additions & 13 deletions Source/Request+AlamofireImage.swift
Expand Up @@ -44,19 +44,34 @@ public final class ImageResponseSerializer: ResponseSerializer {
public let emptyResponseCodes: Set<Int>
public let emptyRequestMethods: Set<HTTPMethod>

static var acceptableImageContentTypes: Set<String> = ["application/octet-stream",
"image/tiff",
"image/jpeg",
"image/gif",
"image/png",
"image/ico",
"image/x-icon",
"image/bmp",
"image/x-bmp",
"image/x-xbitmap",
"image/x-ms-bmp",
"image/x-win-bitmap",
"image/heic"]
static var acceptableImageContentTypes: Set<String> = {
var contentTypes: Set<String> = ["application/octet-stream",
"image/tiff",
"image/jpg",
"image/jpeg",
"image/jp2",
"image/gif",
"image/png",
"image/ico",
"image/x-icon",
"image/bmp",
"image/x-bmp",
"image/x-xbitmap",
"image/x-ms-bmp",
"image/x-win-bitmap"]

#if os(macOS) || os(iOS) // No WebP support on tvOS or watchOS.
if #available(macOS 11, iOS 14, *) {
contentTypes.formUnion(["image/webp"])
}
#endif

if #available(macOS 10.13, iOS 11, tvOS 11, watchOS 4, *) {
contentTypes.formUnion(["image/heic", "image/heif"])
}

return contentTypes
}()

static let streamImageInitialBytePattern = Data([255, 216]) // 0xffd8

Expand Down
6 changes: 3 additions & 3 deletions Source/UIButton+AlamofireImage.swift
Expand Up @@ -244,7 +244,7 @@ extension AlamofireExtension where ExtendedType: UIButton {
strongSelf.setImageRequestReceipt(nil, for: state)

completion?(response)
})
})

setImageRequestReceipt(requestReceipt, for: state)
}
Expand Down Expand Up @@ -413,7 +413,7 @@ extension AlamofireExtension where ExtendedType: UIButton {
strongSelf.setBackgroundImageRequestReceipt(nil, for: state)

completion?(response)
})
})

setBackgroundImageRequestReceipt(requestReceipt, for: state)
}
Expand Down Expand Up @@ -607,7 +607,7 @@ extension UIButton {

// MARK: - Private - AssociatedKeys

private struct AssociatedKeys {
private enum AssociatedKeys {
static var imageDownloader = "UIButton.af.imageDownloader"
static var sharedImageDownloader = "UIButton.af.sharedImageDownloader"
static var imageReceipts = "UIButton.af.imageReceipts"
Expand Down
2 changes: 1 addition & 1 deletion Source/UIImage+AlamofireImage.swift
Expand Up @@ -390,6 +390,6 @@ extension UIImage {

// MARK: -

private struct AssociatedKeys {
private enum AssociatedKeys {
static var isInflated = "UIImage.af.isInflated"
}
4 changes: 2 additions & 2 deletions Source/UIImageView+AlamofireImage.swift
Expand Up @@ -360,7 +360,7 @@ extension AlamofireExtension where ExtendedType: UIImageView {
strongSelf.activeRequestReceipt = nil

completion?(response)
})
})

activeRequestReceipt = requestReceipt
}
Expand Down Expand Up @@ -491,7 +491,7 @@ extension UIImageView {

// MARK: -

private struct AssociatedKeys {
private enum AssociatedKeys {
static var imageDownloader = "UIImageView.af.imageDownloader"
static var sharedImageDownloader = "UIImageView.af.sharedImageDownloader"
static var activeRequestReceipt = "UIImageView.af.activeRequestReceipt"
Expand Down

0 comments on commit e9a13dd

Please sign in to comment.