|
|
@@ -65,13 +65,16 @@ public class KingfisherManager {
|
|
|
/**
|
|
|
* Options to control some downloader and cache behaviors.
|
|
|
*/
|
|
|
- public typealias Options = (forceRefresh: Bool, lowPriority: Bool, cacheMemoryOnly: Bool, shouldDecode: Bool, queue: dispatch_queue_t!)
|
|
|
+ public typealias Options = (forceRefresh: Bool, lowPriority: Bool, cacheMemoryOnly: Bool, shouldDecode: Bool, queue: dispatch_queue_t!, scale: CGFloat)
|
|
|
|
|
|
/// A preset option tuple with all value set to `false`.
|
|
|
- public static var OptionsNone: Options = {
|
|
|
- return (forceRefresh: false, lowPriority: false, cacheMemoryOnly: false, shouldDecode: false, queue: dispatch_get_main_queue())
|
|
|
+ public static let OptionsNone: Options = {
|
|
|
+ return (forceRefresh: false, lowPriority: false, cacheMemoryOnly: false, shouldDecode: false, queue: dispatch_get_main_queue(), scale: 1.0)
|
|
|
}()
|
|
|
|
|
|
+ /// The default set of options to be used by the manager to control some downloader and cache behaviors.
|
|
|
+ public static var DefaultOptions: Options = OptionsNone
|
|
|
+
|
|
|
/// Shared manager used by the extensions across Kingfisher.
|
|
|
public class var sharedManager: KingfisherManager {
|
|
|
return instance
|
|
|
@@ -114,18 +117,16 @@ public class KingfisherManager {
|
|
|
func parseOptionsInfo(optionsInfo: KingfisherOptionsInfo?) -> (Options, ImageCache, ImageDownloader) {
|
|
|
let options: Options
|
|
|
if let optionsInOptionsInfo = optionsInfo?[.Options] as? KingfisherOptions {
|
|
|
- options = (forceRefresh: (optionsInOptionsInfo & KingfisherOptions.ForceRefresh) != KingfisherOptions.None,
|
|
|
- lowPriority: (optionsInOptionsInfo & KingfisherOptions.LowPriority) != KingfisherOptions.None,
|
|
|
- cacheMemoryOnly: (optionsInOptionsInfo & KingfisherOptions.CacheMemoryOnly) != KingfisherOptions.None,
|
|
|
- shouldDecode: (optionsInOptionsInfo & KingfisherOptions.BackgroundDecode) != KingfisherOptions.None,
|
|
|
- queue: dispatch_get_main_queue())
|
|
|
+ let queue = (optionsInOptionsInfo & .BackgroundCallback) != .None ? dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) : KingfisherManager.DefaultOptions.queue
|
|
|
+ let scale = (optionsInOptionsInfo & .ScreenScale) != .None ? UIScreen.mainScreen().scale : KingfisherManager.DefaultOptions.scale
|
|
|
+ options = (forceRefresh: (optionsInOptionsInfo & .ForceRefresh) != .None,
|
|
|
+ lowPriority: (optionsInOptionsInfo & .LowPriority) != .None,
|
|
|
+ cacheMemoryOnly: (optionsInOptionsInfo & .CacheMemoryOnly) != .None,
|
|
|
+ shouldDecode: (optionsInOptionsInfo & .BackgroundDecode) != .None,
|
|
|
+ queue: queue,
|
|
|
+ scale: scale)
|
|
|
} else {
|
|
|
- options = (forceRefresh: false,
|
|
|
- lowPriority: false,
|
|
|
- cacheMemoryOnly: false,
|
|
|
- shouldDecode: false,
|
|
|
- queue: dispatch_get_main_queue()
|
|
|
- )
|
|
|
+ options = KingfisherManager.DefaultOptions
|
|
|
}
|
|
|
|
|
|
let targetCache = optionsInfo?[.TargetCache] as? ImageCache ?? self.cache
|