Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions AlamofireImage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
/* End PBXAggregateTarget section */

/* Begin PBXBuildFile section */
4C0846E7240212E600194A69 /* AlamofireImageExtended.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0846E6240212E600194A69 /* AlamofireImageExtended.swift */; };
4C0846E8240212E600194A69 /* AlamofireImageExtended.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0846E6240212E600194A69 /* AlamofireImageExtended.swift */; };
4C0846E9240212E600194A69 /* AlamofireImageExtended.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0846E6240212E600194A69 /* AlamofireImageExtended.swift */; };
4C0846EA240212E600194A69 /* AlamofireImageExtended.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0846E6240212E600194A69 /* AlamofireImageExtended.swift */; };
4C0893EC1B936A7A005125D9 /* UIImage+AlamofireImageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0893EB1B936A7A005125D9 /* UIImage+AlamofireImageTests.swift */; };
4C0893F51B937404005125D9 /* UIImageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C0893F41B937404005125D9 /* UIImageTests.swift */; };
4C0894E41B9382EB005125D9 /* apple.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 4C0894501B9382EB005125D9 /* apple.jpg */; };
Expand Down Expand Up @@ -577,6 +581,7 @@
3143544B1F4A16FE00266E5F /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
3143544C1F4A16FE00266E5F /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
314354501F4A16FE00266E5F /* CONTRIBUTING.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CONTRIBUTING.md; sourceTree = "<group>"; };
4C0846E6240212E600194A69 /* AlamofireImageExtended.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlamofireImageExtended.swift; sourceTree = "<group>"; };
4C0893EB1B936A7A005125D9 /* UIImage+AlamofireImageTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+AlamofireImageTests.swift"; sourceTree = "<group>"; };
4C0893F41B937404005125D9 /* UIImageTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImageTests.swift; sourceTree = "<group>"; };
4C0894501B9382EB005125D9 /* apple.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = apple.jpg; sourceTree = "<group>"; };
Expand Down Expand Up @@ -942,6 +947,7 @@
isa = PBXGroup;
children = (
4CD5BCE91D7F9D1E0055E232 /* AFIError.swift */,
4C0846E6240212E600194A69 /* AlamofireImageExtended.swift */,
4C8290791B927CE6005E24C8 /* Image.swift */,
4CFC0A051AB4FEC90004D0B8 /* ImageCache.swift */,
4C96A4771AAE9488008AE0B6 /* ImageDownloader.swift */,
Expand Down Expand Up @@ -2056,6 +2062,7 @@
buildActionMask = 2147483647;
files = (
4CFB865F1CA3655F007CE085 /* UIButton+AlamofireImage.swift in Sources */,
4C0846E9240212E600194A69 /* AlamofireImageExtended.swift in Sources */,
4C16B3A11BA93AB700A66EF0 /* ImageCache.swift in Sources */,
4CD5BCEC1D7F9D1E0055E232 /* AFIError.swift in Sources */,
4C16B3A61BA93AB700A66EF0 /* UIImageView+AlamofireImage.swift in Sources */,
Expand Down Expand Up @@ -2092,6 +2099,7 @@
buildActionMask = 2147483647;
files = (
4C86C10A1DA0B30D0032ECC3 /* UIButton+AlamofireImage.swift in Sources */,
4C0846EA240212E600194A69 /* AlamofireImageExtended.swift in Sources */,
4C4D4ECB1B9297BB00C96855 /* ImageCache.swift in Sources */,
4CD5BCED1D7F9D1E0055E232 /* AFIError.swift in Sources */,
4C86C10E1DA0B3160032ECC3 /* UIImageView+AlamofireImage.swift in Sources */,
Expand All @@ -2108,6 +2116,7 @@
buildActionMask = 2147483647;
files = (
4C82907A1B927CE6005E24C8 /* Image.swift in Sources */,
4C0846E7240212E600194A69 /* AlamofireImageExtended.swift in Sources */,
4C96A4781AAE9488008AE0B6 /* ImageDownloader.swift in Sources */,
4CD5BCEA1D7F9D1E0055E232 /* AFIError.swift in Sources */,
4CFC0A091AB52BD90004D0B8 /* ImageFilter.swift in Sources */,
Expand Down Expand Up @@ -2144,6 +2153,7 @@
buildActionMask = 2147483647;
files = (
4C8290781B926F19005E24C8 /* ImageCache.swift in Sources */,
4C0846E8240212E600194A69 /* AlamofireImageExtended.swift in Sources */,
4C82907D1B927DA9005E24C8 /* ImageFilter.swift in Sources */,
4C82907B1B927CE6005E24C8 /* Image.swift in Sources */,
4C86C10D1DA0B3150032ECC3 /* UIImageView+AlamofireImage.swift in Sources */,
Expand Down
62 changes: 62 additions & 0 deletions Source/AlamofireImageExtended.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// AlamofireImageExtended.swift
//
// Copyright (c) 2020 Alamofire Software Foundation (http://alamofire.org/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

/// Type that acts as a generic extension point for all `AlamofireImageExtended` types.
public struct AlamofireImageExtension<ExtendedType> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from needing to make type and init public, we could use AlamofireExtended instead here, and I'd hoped to when adding it to Alamofire. Since we're reusing the af extension point anyway, not duplicating the extension methodology seems like a good idea.

/// Stores the type or metatype of any extended type.
let type: ExtendedType

init(_ type: ExtendedType) {
self.type = type
}
}

// MARK: -

/// Protocol describing the `af` extension points for AlamofireImage extended types.
public protocol AlamofireImageExtended {
/// Type being extended.
associatedtype ExtendedType

/// Static AlamofireImage extension point.
static var af: AlamofireImageExtension<ExtendedType>.Type { get set }
/// Instance AlamofireImage extension point.
var af: AlamofireImageExtension<ExtendedType> { get set }
}

// MARK: -

public extension AlamofireImageExtended {
/// Static AlamofireImage extension point.
static var af: AlamofireImageExtension<Self>.Type {
get { return AlamofireImageExtension<Self>.self }
set {}
}

/// Instance AlamofireImage extension point.
var af: AlamofireImageExtension<Self> {
get { return AlamofireImageExtension(self) }
set {}
}
}
12 changes: 6 additions & 6 deletions Source/ImageFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public struct ScaledToSizeFilter: ImageFilter, Sizable {
/// The filter closure used to create the modified representation of the given image.
public var filter: (Image) -> Image {
return { image in
return image.af_imageScaled(to: self.size)
return image.af.imageScaled(to: self.size)
}
}
}
Expand All @@ -195,7 +195,7 @@ public struct AspectScaledToFitSizeFilter: ImageFilter, Sizable {
/// The filter closure used to create the modified representation of the given image.
public var filter: (Image) -> Image {
return { image in
return image.af_imageAspectScaled(toFit: self.size)
return image.af.imageAspectScaled(toFit: self.size)
}
}
}
Expand All @@ -220,7 +220,7 @@ public struct AspectScaledToFillSizeFilter: ImageFilter, Sizable {
/// The filter closure used to create the modified representation of the given image.
public var filter: (Image) -> Image {
return { image in
return image.af_imageAspectScaled(toFill: self.size)
return image.af.imageAspectScaled(toFill: self.size)
}
}
}
Expand Down Expand Up @@ -253,7 +253,7 @@ public struct RoundedCornersFilter: ImageFilter, Roundable {
/// The filter closure used to create the modified representation of the given image.
public var filter: (Image) -> Image {
return { image in
return image.af_imageRounded(
return image.af.imageRounded(
withCornerRadius: self.radius,
divideRadiusByImageScale: self.divideRadiusByImageScale
)
Expand All @@ -279,7 +279,7 @@ public struct CircleFilter: ImageFilter {
/// The filter closure used to create the modified representation of the given image.
public var filter: (Image) -> Image {
return { image in
return image.af_imageRoundedIntoCircle()
return image.af.imageRoundedIntoCircle()
}
}
}
Expand All @@ -303,7 +303,7 @@ public extension ImageFilter where Self: CoreImageFilter {
/// The filter closure used to create the modified representation of the given image.
var filter: (Image) -> Image {
return { image in
return image.af_imageFiltered(withCoreImageFilter: self.filterName, parameters: self.parameters) ?? image
return image.af.imageFiltered(withCoreImageFilter: self.filterName, parameters: self.parameters) ?? image
}
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Request+AlamofireImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ public final class ImageResponseSerializer: ResponseSerializer {
}

#if os(iOS) || os(tvOS) || os(watchOS)
guard let image = UIImage.af_threadSafeImage(with: data, scale: imageScale) else {
guard let image = UIImage.af.threadSafeImage(with: data, scale: imageScale) else {
throw AFIError.imageSerializationFailed
}

if inflateResponseImage { image.af_inflate() }
if inflateResponseImage { image.af.inflate() }
#elseif os(macOS)
guard let bitmapImage = NSBitmapImageRep(data: data) else {
throw AFIError.imageSerializationFailed
Expand Down
Loading