From b17cf0bf380a4faaf73b2e31908ad2fb9d71557f Mon Sep 17 00:00:00 2001 From: kean Date: Sat, 19 Sep 2015 15:22:30 +0300 Subject: [PATCH] Add Pod files to workspace for easy access; Cleanup --- .../Nuke.xcworkspace/contents.xcworkspacedata | 79 +++++++++++++++++++ Pod/Classes/Core/ImageManager.swift | 4 +- Pod/Classes/Core/ImageManagerExtensions.swift | 8 +- README.md | 8 +- 4 files changed, 85 insertions(+), 14 deletions(-) diff --git a/Example/Nuke.xcworkspace/contents.xcworkspacedata b/Example/Nuke.xcworkspace/contents.xcworkspacedata index 88af0a758..5c5ab802a 100644 --- a/Example/Nuke.xcworkspace/contents.xcworkspacedata +++ b/Example/Nuke.xcworkspace/contents.xcworkspacedata @@ -4,6 +4,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pod/Classes/Core/ImageManager.swift b/Pod/Classes/Core/ImageManager.swift index 5eea9634f..312b44473 100644 --- a/Pod/Classes/Core/ImageManager.swift +++ b/Pod/Classes/Core/ImageManager.swift @@ -37,7 +37,7 @@ public struct ImageManagerConfiguration { public var dataLoader: ImageDataLoading public var decoder: ImageDecoding public var cache: ImageMemoryCaching? - public var maxConcurrentPreheatingRequests = 2 + public var maxConcurrentPreheatingTasks = 2 public init(dataLoader: ImageDataLoading, decoder: ImageDecoding = ImageDecoder(), cache: ImageMemoryCaching? = ImageMemoryCache()) { self.dataLoader = dataLoader @@ -194,7 +194,7 @@ public class ImageManager: ImageManaging, ImageManagerLoaderDelegate, ImageTaskM var executingTaskCount = self.executingTasks.count let sortedPreheatingTasks = self.preheatingTasks.values.sort { $0.tag < $1.tag } for task in sortedPreheatingTasks { - if executingTaskCount > self.configuration.maxConcurrentPreheatingRequests { + if executingTaskCount > self.configuration.maxConcurrentPreheatingTasks { break } if task.state == .Suspended { diff --git a/Pod/Classes/Core/ImageManagerExtensions.swift b/Pod/Classes/Core/ImageManagerExtensions.swift index 87754102a..8e4747dc2 100644 --- a/Pod/Classes/Core/ImageManagerExtensions.swift +++ b/Pod/Classes/Core/ImageManagerExtensions.swift @@ -5,18 +5,12 @@ import UIKit extension ImageManager { - private static var sharedManagerIvar: ImageManaging! + private static var sharedManagerIvar: ImageManaging = ImageManager(configuration: ImageManagerConfiguration(dataLoader: ImageDataLoader())) private static var lock = OS_SPINLOCK_INIT private static var token: dispatch_once_t = 0 public class func shared() -> ImageManaging { var manager: ImageManaging - dispatch_once(&token) { - if self.sharedManagerIvar == nil { - let conf = ImageManagerConfiguration(dataLoader: ImageDataLoader(), cache: ImageMemoryCache()) - self.sharedManagerIvar = ImageManager(configuration: conf) - } - } OSSpinLockLock(&lock) manager = sharedManagerIvar OSSpinLockUnlock(&lock) diff --git a/README.md b/README.md index 40bc36824..f80315bef 100644 --- a/README.md +++ b/README.md @@ -93,8 +93,7 @@ Nuke.taskWithRequest(request) { ```swift let task = Nuke.taskWithURL(imageURL) { let image = $0.image -} -task.resume() +}.resume() // Use progress object to track load progress let progress = task.progress @@ -109,7 +108,7 @@ task.cancel() #### UICollectionView ```swift -override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { +func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellReuseID, forIndexPath: indexPath) let imageView: ImageView = <#view#> @@ -123,7 +122,7 @@ override func collectionView(collectionView: UICollectionView, cellForItemAtInde Cancel image task as soon as the cell goes offscreen (optional): ```swift -override func collectionView(collectionView: UICollectionView, didEndDisplayingCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) { +func collectionView(collectionView: UICollectionView, didEndDisplayingCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) { let imageView: ImageView = <#view#> imageView.prepareForReuse() } @@ -167,7 +166,6 @@ let composition = ImageDecoderComposition(decoders: [decoder1, decoder2]) ```swift let requests = [ImageRequest(URL: imageURL1), ImageRequest(URL: imageURL2)] Nuke.startPreheatingImages(requests: requests) - Nuke.stopPreheatingImages(requests: requests) ```