-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature customizable default cache serializer #1373
Feature customizable default cache serializer #1373
Conversation
|
||
|
||
/// The compression quality when converting image to a lossy format data. Default is 1.0. | ||
public var compressionQuality: CGFloat = 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it have to be CGFloat
? Can't it be a Double
as it was?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compressionQuality might be defined as an enumeration with a default value set to high.
public var compressionQuality: JPEGCompressionLevel = .high
enum JPEGCompressionLevel {
case custom(Double)
case max, high, med, low
var rawValue: Double {
switch self {
case .max:
return 1.0
case .high:
return 0.9
case .med:
return 0.5
case .low:
return 0.2
case .custom(let customValue):
return customValue
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UIImage
receives a CGFloat
when converting to JPEG data: https://developer.apple.com/documentation/uikit/uiimage/1624115-jpegdata
So I guess keeping them aligned would reduce the mental pressure of users.
What do you mean by "a Double
as it was"? I don't think this value once being a Double
anywhere... 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made the mistaken assumption about the original type of the compressionQuality property because CoreGraphics library was imported.
Below, updated code proposition.
enum JPEGCompressionLevel {
case custom(CGFloat)
case max, high, med, low
var rawValue: CGFloat {
switch self {
case .max:
return 1.0
case .high:
return 0.9
case .med:
return 0.5
case .low:
return 0.2
case .custom(let customValue):
return customValue
}
}
}
Example of use:
var cacheSerializer = DefaultCacheSerializer()
cacheSerializer.compressionQuality = .max
cacheSerializer.compressionQuality = .custom(0.8)
…ault-cache-serializer Feature customizable default cache serializer
For #1362