Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Apr 24, 2015
1 parent a05f287 commit 7bdbbde
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'Kingfisher', '~> 1.1'
pod 'Kingfisher', '~> 1.2'
```

Then, run the following command:
Expand All @@ -72,7 +72,7 @@ $ brew install carthage
To integrate Kingfisher into your Xcode project using CocoaPods, specify it in your `Cartfile`:

```ogdl
github "onevcat/Kingfisher" >= 1.1
github "onevcat/Kingfisher" >= 1.2
```

Then, run the following command to build the Kingfisher framework:
Expand Down Expand Up @@ -142,15 +142,25 @@ imageView.kf_setImageWithURL(NSURL(string: "http://your_image_url.png")!, placeh

#### Options

Kingfisher will search in cache (both memory and disk) first with the URL, if no image found, it will try to download and store the image in the cache. You can change this behavior by passing an option, to let it ignore the cache.
Kingfisher will search in cache (both memory and disk) first with the URL, if no image found, it will try to download and store the image in the cache. You can change this behavior by passing an option dictionary, to let it ignore the cache.

```swift
imageView.kf_setImageWithURL(NSURL(string: "your_image_url")!,
placeholderImage: nil,
options: KingfisherOptions.ForceRefresh)
optionsInfo: [.Options: KingfisherOptions.ForceRefresh])
```

There are also other options to control the cache level, downloading priority, etc. See [documentation](http://cocoadocs.org/docsets/Kingfisher/0.0.2/Structs/KingfisherOptions.html) for more.
There are also other options to control the cache level, downloading priority, etc. Take another example, if you need to cache the downloaded image to a customized cache instead of the default one:

```swift
let myCache = ImageCache(name: "my_cache")

imageView.kf_setImageWithURL(NSURL(string: "your_image_url")!,
placeholderImage: nil,
optionsInfo: [.TargetCache: myCache])
```

This is useful if you want to use a specified cache for some reasons. For more information about options, please see the `KingfisherOptionsInfo` in the [documentation](http://cocoadocs.org/docsets/Kingfisher/index.html).

#### Callbacks

Expand All @@ -159,7 +169,7 @@ You can get a chance during Kingfisher downloading images and when the process i
```swift
imageView.kf_setImageWithURL(NSURL(string: "your_image_url")!,
placeholderImage: nil,
options: KingfisherOptions.None,
optionsInfo: nil,
progressBlock: { (receivedSize, totalSize) -> () in
println("Download Progress: \(receivedSize)/\(totalSize)")
},
Expand Down Expand Up @@ -188,15 +198,35 @@ Kingfisher will use the default downloader and cache if you do not specify them

```swift
let downloader = KingfisherManager.sharedManager.downloader
downloader.downloadTimeout = 5 // Download process will timeout after 5 seconds. Default is 15.

// Download process will timeout after 5 seconds. Default is 15.
downloader.downloadTimeout = 5

// requestModifier will be called before image download request made.
downloader.requestModifier = {
(request: NSMutableURLRequest) in
// Do what you need to modify the download request. Maybe add your HTTP basic authentication for example.
}

// Hosts in trustedHosts will be ignore the received challenge.
// You can add the host of your self-signed site to it to bypass the SSL.
// (Do not do it unless you know what you are doing)
downloader.trustedHosts = Set(["your_self_signed_host"])
```

```swift
let cache = KingfisherManager.sharedManager.cache

// Set max disk cache to 50 mb. Default is no limit.
cache.maxDiskCacheSize = 50 * 1024 * 1024

// Set max disk cache to duration to 3 days, Default is 1 week.
cache.maxCachePeriodInSecond = 60 * 60 * 24 * 3

// Get the disk size taken by the cache.
cache.calculateDiskCacheSizeWithCompletionHandler { (size) -> () in
println("disk size in bytes: \(size)")
}
```

The memory cache will be purged whenever the app switched to background or receiving a memory warning. Disk cache will be cleaned when the conditions are met. You can also clear these caches manually:
Expand Down

0 comments on commit 7bdbbde

Please sign in to comment.