Skip to content

Commit

Permalink
Formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jshier committed Aug 3, 2023
1 parent 9ef9041 commit 07ffd9c
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 141 deletions.
8 changes: 4 additions & 4 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

--exclude Carthage
--symlinks ignore
--swiftversion 5.3
--swiftversion 5.5

# rules
--enable isEmpty
Expand All @@ -25,6 +25,6 @@
--nospaceoperators ..<, ...
--selfrequired validate
--stripunusedargs closure-only
--wraparguments after-first
--wrapcollections after-first
--wrapparameters after-first
--wraparguments preserve
--wrapcollections preserve
--wrapparameters preserve
14 changes: 7 additions & 7 deletions Source/ImageFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public protocol Roundable {
extension ImageFilter where Self: Roundable {
/// The unique idenitifier for an `ImageFilter` conforming to the `Roundable` protocol.
public var identifier: String {
let radius = Int64(self.radius.rounded())
let radius = Int64(radius.rounded())
return "\(type(of: self))-radius:(\(radius))"
}
}
Expand Down 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 {
{ image in
image.af.imageScaled(to: self.size)
image.af.imageScaled(to: 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 {
{ image in
image.af.imageAspectScaled(toFit: self.size)
image.af.imageAspectScaled(toFit: 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 {
{ image in
image.af.imageAspectScaled(toFill: self.size)
image.af.imageAspectScaled(toFill: size)
}
}
}
Expand Down Expand Up @@ -253,14 +253,14 @@ public struct RoundedCornersFilter: ImageFilter, Roundable {
/// The filter closure used to create the modified representation of the given image.
public var filter: (Image) -> Image {
{ image in
image.af.imageRounded(withCornerRadius: self.radius,
divideRadiusByImageScale: self.divideRadiusByImageScale)
image.af.imageRounded(withCornerRadius: radius,
divideRadiusByImageScale: divideRadiusByImageScale)
}
}

/// The unique idenitifier for an `ImageFilter` conforming to the `Roundable` protocol.
public var identifier: String {
let radius = Int64(self.radius.rounded())
let radius = Int64(radius.rounded())
return "\(type(of: self))-radius:(\(radius))-divided:(\(divideRadiusByImageScale))"
}
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Request+AlamofireImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ public final class ImageResponseSerializer: ResponseSerializer {
contentTypes.insert("image/webp")
}
#endif

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

#if !os(watchOS)
if #available(macOS 13.0, iOS 16.0, tvOS 16.0, *) {
contentTypes.insert("image/avif")
}
#endif

if #available(macOS 14.0, iOS 17.0, tvOS 17.0, watchOS 10.0, *) {
contentTypes.insert("image/jxl")
}
Expand Down
8 changes: 4 additions & 4 deletions Source/UIButton+AlamofireImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ extension AlamofireExtension where ExtendedType: UIButton {

cancelImageRequest(for: state)

let imageDownloader = self.imageDownloader ?? UIButton.af.sharedImageDownloader
let imageDownloader = imageDownloader ?? UIButton.af.sharedImageDownloader
let imageCache = imageDownloader.imageCache

// Use the image from the image cache if it exists
Expand Down Expand Up @@ -253,7 +253,7 @@ extension AlamofireExtension where ExtendedType: UIButton {
public func cancelImageRequest(for state: ControlState) {
guard let receipt = imageRequestReceipt(for: state) else { return }

let imageDownloader = self.imageDownloader ?? UIButton.af.sharedImageDownloader
let imageDownloader = imageDownloader ?? UIButton.af.sharedImageDownloader
imageDownloader.cancelRequest(with: receipt)

setImageRequestReceipt(nil, for: state)
Expand Down Expand Up @@ -351,7 +351,7 @@ extension AlamofireExtension where ExtendedType: UIButton {

cancelBackgroundImageRequest(for: state)

let imageDownloader = self.imageDownloader ?? UIButton.af.sharedImageDownloader
let imageDownloader = imageDownloader ?? UIButton.af.sharedImageDownloader
let imageCache = imageDownloader.imageCache

// Use the image from the image cache if it exists
Expand Down Expand Up @@ -422,7 +422,7 @@ extension AlamofireExtension where ExtendedType: UIButton {
public func cancelBackgroundImageRequest(for state: ControlState) {
guard let receipt = backgroundImageRequestReceipt(for: state) else { return }

let imageDownloader = self.imageDownloader ?? UIButton.af.sharedImageDownloader
let imageDownloader = imageDownloader ?? UIButton.af.sharedImageDownloader
imageDownloader.cancelRequest(with: receipt)

setBackgroundImageRequestReceipt(nil, for: state)
Expand Down
9 changes: 4 additions & 5 deletions Source/UIImage+AlamofireImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,11 @@ extension AlamofireExtension where ExtendedType: UIImage {
public var containsAlphaComponent: Bool {
let alphaInfo = type.cgImage?.alphaInfo

return (
return
alphaInfo == .first ||
alphaInfo == .last ||
alphaInfo == .premultipliedFirst ||
alphaInfo == .premultipliedLast
)
alphaInfo == .last ||
alphaInfo == .premultipliedFirst ||
alphaInfo == .premultipliedLast
}

/// Returns whether the image is opaque.
Expand Down
4 changes: 2 additions & 2 deletions Source/UIImageView+AlamofireImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ extension AlamofireExtension where ExtendedType: UIImageView {

cancelImageRequest()

let imageDownloader = self.imageDownloader ?? UIImageView.af.sharedImageDownloader
let imageDownloader = imageDownloader ?? UIImageView.af.sharedImageDownloader
let imageCache = imageDownloader.imageCache

// Use the image from the image cache if it exists
Expand Down Expand Up @@ -371,7 +371,7 @@ extension AlamofireExtension where ExtendedType: UIImageView {
public func cancelImageRequest() {
guard let activeRequestReceipt = activeRequestReceipt else { return }

let imageDownloader = self.imageDownloader ?? UIImageView.af.sharedImageDownloader
let imageDownloader = imageDownloader ?? UIImageView.af.sharedImageDownloader
imageDownloader.cancelRequest(with: activeRequestReceipt)

self.activeRequestReceipt = nil
Expand Down
32 changes: 16 additions & 16 deletions Tests/ImageCacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatItCanAddImageToCacheWithIdentifier() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let identifier = "unicorn"

// When
Expand All @@ -75,7 +75,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatItCanAddImageToCacheWithRequestIdentifier() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let request = Endpoint.get.urlRequest
let identifier = "-unicorn"

Expand Down Expand Up @@ -137,7 +137,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatItCanRemoveImageFromCacheWithIdentifier() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let identifier = "unicorn"

// When
Expand All @@ -155,7 +155,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatItCanRemoveImageFromCacheWithRequestIdentifier() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let request = Endpoint.get.urlRequest
let identifier = "unicorn"

Expand All @@ -174,7 +174,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatItCanRemoveImagesFromCacheMatchingRequestIdentifier() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let request = Endpoint.get.urlRequest

let identifier1 = "unicorn-100"
Expand All @@ -201,7 +201,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatItCanRemoveAllImagesFromCache() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let identifier = "unicorn"

// When
Expand All @@ -221,7 +221,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatItRemovesAllImagesFromCacheWhenReceivingMemoryWarningNotification() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let identifier = "unicorn"

// When
Expand All @@ -245,7 +245,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatItCanFetchImageFromCacheWithIdentifier() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let identifier = "unicorn"

// When
Expand All @@ -260,7 +260,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatItCanFetchImageFromCacheWithRequestIdentifier() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let request = Endpoint.get.urlRequest
let identifier = "unicorn"

Expand All @@ -278,7 +278,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatItIncrementsMemoryUsageWhenAddingImageToCache() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let identifier = "unicorn"

// When
Expand All @@ -293,7 +293,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatItDecrementsMemoryUsageWhenRemovingImageFromCache() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let identifier = "unicorn"

// When
Expand All @@ -309,7 +309,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatItDecrementsMemoryUsageWhenRemovingAllImagesFromCache() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let identifier = "unicorn"

// When
Expand All @@ -327,7 +327,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatItPurgesImagesWhenMemoryCapacityIsReached() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let identifier = "unicorn"

var memoryUsage: [UInt64] = []
Expand All @@ -347,7 +347,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatItPrioritizesImagesWithOldestLastAccessDatesDuringPurge() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let identifier = "unicorn"

// When
Expand All @@ -369,7 +369,7 @@ final class ImageCacheTestCase: BaseTestCase {

func testThatAccessingCachedImageUpdatesLastAccessDate() {
// Given
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")
let identifier = "unicorn"

// When
Expand Down Expand Up @@ -400,7 +400,7 @@ final class ImageCacheThreadSafetyTests: BaseTestCase {
func testMultipleReadsAndWrites() {
// Given
let cache = AutoPurgingImageCache(memoryCapacity: 1_000_000, preferredMemoryUsageAfterPurge: 100_000)
let image = self.image(forResource: "unicorn", withExtension: "png")
let image = image(forResource: "unicorn", withExtension: "png")

// When
DispatchQueue.concurrentPerform(iterations: 100) { iteration in
Expand Down
Loading

0 comments on commit 07ffd9c

Please sign in to comment.