Skip to content
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

Replace all 'url' with 'URL'. #1

Merged
merged 1 commit into from
Apr 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions Kingfisher/ImageCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ extension ImageCache {
let resourceKeys = [NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey]
let expiredDate = NSDate(timeIntervalSinceNow: -self.maxCachePeriodInSecond)
var cachedFiles = [NSURL: [NSObject: AnyObject]]()
var urlsToDelete = [NSURL]()
var URLsToDelete = [NSURL]()

var diskCacheSize: UInt = 0

Expand All @@ -366,10 +366,10 @@ extension ImageCache {
}
}

// If this file is expired, add it to urlsToDelete
// If this file is expired, add it to URLsToDelete
if let modificationDate = resourceValues[NSURLContentModificationDateKey] as? NSDate {
if modificationDate.laterDate(expiredDate) == expiredDate {
urlsToDelete.append(fileURL)
URLsToDelete.append(fileURL)
continue
}
}
Expand All @@ -383,7 +383,7 @@ extension ImageCache {
}
}

for fileURL in urlsToDelete {
for fileURL in URLsToDelete {
self.fileManager.removeItemAtURL(fileURL, error: nil)
}

Expand Down
52 changes: 26 additions & 26 deletions Kingfisher/ImageDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,48 +47,48 @@ public class ImageDownloader: NSObject {
// MARK: - Download method
public extension ImageDownloader {
/**
Download an image with a url.
Download an image with a URL.

:param: url Target url.
:param: URL Target URL.
:param: progressBlock Called when the download progress updated.
:param: completionHandler Called when the download progress finishes.
*/
public func downloadImageWithURL(url: NSURL,
public func downloadImageWithURL(URL: NSURL,
progressBlock: ImageDownloaderProgressBlock?,
completionHandler: ImageDownloaderCompletionHandler?)
{
downloadImageWithURL(url, options: KingfisherManager.OptionsNone, progressBlock: progressBlock, completionHandler: completionHandler)
downloadImageWithURL(URL, options: KingfisherManager.OptionsNone, progressBlock: progressBlock, completionHandler: completionHandler)
}

/**
Download an image with a url and option.
Download an image with a URL and option.

:param: url Target url.
:param: URL Target URL.
:param: options The options could control download behavior. See `KingfisherManager.Options`
:param: progressBlock Called when the download progress updated.
:param: completionHandler Called when the download progress finishes.
*/
public func downloadImageWithURL(url: NSURL,
public func downloadImageWithURL(URL: NSURL,
options: KingfisherManager.Options,
progressBlock: ImageDownloaderProgressBlock?,
completionHandler: ImageDownloaderCompletionHandler?)
{
downloadImageWithURL(url,
downloadImageWithURL(URL,
retrieveImagetask: nil,
options: options,
progressBlock: progressBlock,
completionHandler: completionHandler)
}

internal func downloadImageWithURL(url: NSURL,
internal func downloadImageWithURL(URL: NSURL,
retrieveImagetask: RetrieveImageTask?,
options: KingfisherManager.Options,
progressBlock: ImageDownloaderProgressBlock?,
completionHandler: ImageDownloaderCompletionHandler?)
{
setupProgressBlock(progressBlock, completionHandler: completionHandler, forURL: url) {(session, fetchLoad) -> Void in
setupProgressBlock(progressBlock, completionHandler: completionHandler, forURL: URL) {(session, fetchLoad) -> Void in
let timeout = self.downloadTimeout == 0.0 ? 15.0 : self.downloadTimeout
let request = NSMutableURLRequest(URL: url, cachePolicy: .ReloadIgnoringLocalCacheData, timeoutInterval: timeout)
let request = NSMutableURLRequest(URL: URL, cachePolicy: .ReloadIgnoringLocalCacheData, timeoutInterval: timeout)
request.HTTPShouldUsePipelining = true
let task = session.dataTaskWithRequest(request)

Expand All @@ -102,20 +102,20 @@ public extension ImageDownloader {
}

// A single key may have multiple callbacks. Only download once.
internal func setupProgressBlock(progressBlock: ImageDownloaderProgressBlock?, completionHandler: ImageDownloaderCompletionHandler?, forURL url: NSURL, started: ((NSURLSession, ImageFetchLoad) -> Void)) {
internal func setupProgressBlock(progressBlock: ImageDownloaderProgressBlock?, completionHandler: ImageDownloaderCompletionHandler?, forURL URL: NSURL, started: ((NSURLSession, ImageFetchLoad) -> Void)) {

dispatch_barrier_sync(barrierQueue, { () -> Void in

var create = false
var loadObjectForURL = self.fetchLoads[url]
var loadObjectForURL = self.fetchLoads[URL]
if loadObjectForURL == nil {
create = true
loadObjectForURL = ImageFetchLoad()
}

let callbackPair = (progressBlock: progressBlock, completionHander: completionHandler)
loadObjectForURL!.callbacks.append(callbackPair)
self.fetchLoads[url] = loadObjectForURL!
self.fetchLoads[URL] = loadObjectForURL!

if create {
let session = NSURLSession(configuration: NSURLSessionConfiguration.ephemeralSessionConfiguration(), delegate: self, delegateQueue:NSOperationQueue.mainQueue())
Expand All @@ -124,9 +124,9 @@ public extension ImageDownloader {
})
}

func cleanForURL(url: NSURL) {
func cleanForURL(URL: NSURL) {
dispatch_barrier_sync(barrierQueue, { () -> Void in
self.fetchLoads.removeValueForKey(url)
self.fetchLoads.removeValueForKey(URL)
return
})
}
Expand All @@ -137,7 +137,7 @@ extension ImageDownloader: NSURLSessionDataDelegate {

public func URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didReceiveResponse response: NSURLResponse, completionHandler: (NSURLSessionResponseDisposition) -> Void) {

if let url = dataTask.originalRequest.URL, callbackPairs = fetchLoads[url]?.callbacks {
if let URL = dataTask.originalRequest.URL, callbackPairs = fetchLoads[URL]?.callbacks {
for callbackPair in callbackPairs {
callbackPair.progressBlock?(receivedSize: 0, totalSize: response.expectedContentLength)
}
Expand All @@ -147,7 +147,7 @@ extension ImageDownloader: NSURLSessionDataDelegate {

public func URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didReceiveData data: NSData) {

if let url = dataTask.originalRequest.URL, fetchLoad = fetchLoads[url] {
if let URL = dataTask.originalRequest.URL, fetchLoad = fetchLoads[URL] {
fetchLoad.responsData.appendData(data)
for callbackPair in fetchLoad.callbacks {
callbackPair.progressBlock?(receivedSize: Int64(fetchLoad.responsData.length), totalSize: dataTask.response!.expectedContentLength)
Expand All @@ -165,31 +165,31 @@ extension ImageDownloader: NSURLSessionDataDelegate {

public func URLSession(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError error: NSError?) {

let url = task.originalRequest.URL!
let URL = task.originalRequest.URL!

if let error = error { // Error happened
callbackWithImage(nil, error: error, imageURL: url)
callbackWithImage(nil, error: error, imageURL: URL)
} else { //Download finished without error

// We are on main queue when receiving this.
dispatch_async(processQueue, { () -> Void in

if let fetchLoad = self.fetchLoads[url] {
if let fetchLoad = self.fetchLoads[URL] {
if let image = UIImage(data: fetchLoad.responsData) {
if fetchLoad.shouldDecode {
self.callbackWithImage(image.kf_decodedImage(), error: nil, imageURL: url)
self.callbackWithImage(image.kf_decodedImage(), error: nil, imageURL: URL)
} else {
self.callbackWithImage(image, error: nil, imageURL: url)
self.callbackWithImage(image, error: nil, imageURL: URL)
}

} else {
self.callbackWithImage(nil, error: NSError(domain: KingfisherErrorDomain, code: KingfisherError.BadData.rawValue, userInfo: nil), imageURL: url)
self.callbackWithImage(nil, error: NSError(domain: KingfisherErrorDomain, code: KingfisherError.BadData.rawValue, userInfo: nil), imageURL: URL)
}
} else {
self.callbackWithImage(nil, error: NSError(domain: KingfisherErrorDomain, code: KingfisherError.BadData.rawValue, userInfo: nil), imageURL: url)
self.callbackWithImage(nil, error: NSError(domain: KingfisherErrorDomain, code: KingfisherError.BadData.rawValue, userInfo: nil), imageURL: URL)
}

self.cleanForURL(url)
self.cleanForURL(URL)
})
}
}
Expand Down
22 changes: 11 additions & 11 deletions Kingfisher/KingfisherManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@ public class KingfisherManager {
}

/**
Get an image with url as the key.
Get an image with URL as the key.
If KingfisherOptions.None is used as `options`, Kingfisher will seek the image in memory and disk first.
If not found, it will download the image at url and cache it.
If not found, it will download the image at URL and cache it.
These default behaviors could be adjusted by passing different options. See `KingfisherOptions` for more.

:param: url The image url.
:param: URL The image URL.
:param: options Options controlling manager behavior.
:param: progressBlock Called every time downloaded data changed. This could be used as a progress UI.
:param: completionHandler Called when the whole retriving process finished.

:returns: A `RetrieveImageTask` task object. You can use this object to cancel the task.
*/
public func retriveImageWithURL(url: NSURL,
public func retriveImageWithURL(URL: NSURL,
options: KingfisherOptions,
progressBlock:DownloadProgressBlock?,
completionHandler:CompletionHandler?) -> RetrieveImageTask
Expand All @@ -118,9 +118,9 @@ public class KingfisherManager {
cacheMemoryOnly: options & KingfisherOptions.CacheMemoryOnly != KingfisherOptions.None,
shouldDecode: options & KingfisherOptions.BackgroundDecode != KingfisherOptions.None)

if let key = url.absoluteString {
if let key = URL.absoluteString {
if options.forceRefresh {
downloadAndCacheImageWithURL(url,
downloadAndCacheImageWithURL(URL,
forKey: key,
retrieveImageTask: task,
progressBlock: progressBlock,
Expand All @@ -129,9 +129,9 @@ public class KingfisherManager {
} else {
let diskTask = cache.retrieveImageForKey(key, options: options, completionHandler: { (image, cacheType) -> () in
if image != nil {
completionHandler?(image: image, error: nil, imageURL: url)
completionHandler?(image: image, error: nil, imageURL: URL)
} else {
self.downloadAndCacheImageWithURL(url,
self.downloadAndCacheImageWithURL(URL,
forKey: key,
retrieveImageTask: task,
progressBlock: progressBlock,
Expand All @@ -146,18 +146,18 @@ public class KingfisherManager {
return task
}

func downloadAndCacheImageWithURL(url: NSURL,
func downloadAndCacheImageWithURL(URL: NSURL,
forKey key: String,
retrieveImageTask: RetrieveImageTask,
progressBlock: DownloadProgressBlock?,
completionHandler: CompletionHandler?,
options: Options)
{
downloader.downloadImageWithURL(url, retrieveImagetask: retrieveImageTask, options: options, progressBlock: { (receivedSize, totalSize) -> () in
downloader.downloadImageWithURL(URL, retrieveImagetask: retrieveImageTask, options: options, progressBlock: { (receivedSize, totalSize) -> () in
progressBlock?(receivedSize: receivedSize, totalSize: totalSize)
return
}) { (image, error, imageURL) -> () in
completionHandler?(image: image, error: error, imageURL: url)
completionHandler?(image: image, error: error, imageURL: URL)
if let image = image {
self.cache.storeImage(image, forKey: key, toDisk: !options.cacheMemoryOnly, completionHandler: nil)
}
Expand Down
Loading