Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
# AlamofireImage
2
 
3
[![Build Status](https://travis-ci.org/Alamofire/AlamofireImage.svg?branch=master)](https://travis-ci.org/Alamofire/AlamofireImage)
4
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/AlamofireImage.svg)](https://img.shields.io/cocoapods/v/AlamofireImage.svg)
5
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
6
[![Platform](https://img.shields.io/cocoapods/p/AlamofireImage.svg?style=flat)](http://cocoadocs.org/docsets/AlamofireImage)
7
[![Twitter](https://img.shields.io/badge/twitter-@AlamofireSF-blue.svg?style=flat)](http://twitter.com/AlamofireSF)
8
[![Gitter](https://badges.gitter.im/Alamofire/Alamofire.svg)](https://gitter.im/Alamofire/Alamofire?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
9
 
10
AlamofireImage is an image component library for Alamofire.
11
 
12
## Features
13
 
14
- [x] Image Response Serializers
15
- [x] UIImage Extensions for Inflation / Scaling / Rounding / CoreImage
16
- [x] Single and Multi-Pass Image Filters
17
- [x] Auto-Purging In-Memory Image Cache
18
- [x] Prioritized Queue Order Image Downloading
19
- [x] Authentication with URLCredential
20
- [x] UIImageView Async Remote Downloads with Placeholders
21
- [x] UIImageView Filters and Transitions
22
- [x] Comprehensive Test Coverage
23
- [x] [Complete Documentation](https://alamofire.github.io/AlamofireImage/)
24
 
25
## Requirements
26
 
27
- iOS 10.0+ / macOS 10.12+ / tvOS 10.0+ / watchOS 3.0+
28
- Xcode 11+
29
- Swift 5.1+
30
 
31
## Migration Guides
32
 
33
- [AlamofireImage 2.0 Migration Guide](https://github.com/Alamofire/AlamofireImage/blob/master/Documentation/AlamofireImage%202.0%20Migration%20Guide.md)
34
- [AlamofireImage 3.0 Migration Guide](https://github.com/Alamofire/AlamofireImage/blob/master/Documentation/AlamofireImage%203.0%20Migration%20Guide.md)
35
- [AlamofireImage 4.0 Migration Guide](https://github.com/Alamofire/AlamofireImage/blob/master/Documentation/AlamofireImage%204.0%20Migration%20Guide.md)
36
 
37
## Dependencies
38
 
39
- [Alamofire 5.1+](https://github.com/Alamofire/Alamofire)
40
 
41
## Communication
42
 
43
- If you need to **find or understand an API**, check [our documentation](https://alamofire.github.io/AlamofireImage/).
44
- If you need **help with an AlamofireImage feature**, use [our forum on swift.org](https://forums.swift.org/c/related-projects/alamofire).
45
- If you'd like to **discuss AlamofireImage best practices**, use [our forum on swift.org](https://forums.swift.org/c/related-projects/alamofire).
46
- If you'd like to **discuss a feature request**, use [our forum on swift.org](https://forums.swift.org/c/related-projects/alamofire).
47
- If you **found a bug**, open an issue and follow the guide. The more detail the better!
48
- If you **want to contribute**, submit a pull request.
49
 
50
## Installation
51
 
52
### CocoaPods
53
 
54
[CocoaPods](https://cocoapods.org) is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate AlamofireImage into your Xcode project using CocoaPods, specify it in your `Podfile`:
55
 
56
```ruby
57
pod 'AlamofireImage', '~> 4.1'
58
```
59
 
60
### Carthage
61
 
62
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate AlamofireImage into your Xcode project using Carthage, specify it in your `Cartfile`:
63
 
64
```ogdl
65
github "Alamofire/AlamofireImage" ~> 4.1
66
```
67
 
68
### Swift Package Manager
69
 
70
The [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler. It is in early development, but AlamofireImage does support its use on supported platforms.
71
 
72
Once you have your Swift package set up, adding AlamofireImage as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.
73
 
74
```swift
75
dependencies: [
76
    .package(url: "https://github.com/Alamofire/AlamofireImage.git", .upToNextMajor(from: "4.2.0"))
77
]
78
```
79
 
80
### Manually
81
 
82
If you prefer not to use either of the aforementioned dependency managers, you can integrate AlamofireImage into your project manually.
83
 
84
#### Embedded Framework
85
 
86
- Open up Terminal, `cd` into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:
87
 
88
```bash
89
$ git init
90
```
91
 
92
- Add AlamofireImage as a git [submodule](http://git-scm.com/docs/git-submodule) by running the following command:
93
 
94
```bash
95
$ git submodule add https://github.com/Alamofire/AlamofireImage.git
96
```
97
 
98
- Open the new `AlamofireImage` folder, and drag the `AlamofireImage.xcodeproj` into the Project Navigator of your application's Xcode project.
99
 
100
    > It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.
101
 
102
- Select the `AlamofireImage.xcodeproj` in the Project Navigator and verify the deployment target matches that of your application target.
103
- Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
104
- In the tab bar at the top of that window, open the "General" panel.
105
- Click on the `+` button under the "Embedded Binaries" section.
106
- You will see two different `AlamofireImage.xcodeproj` folders each with two different versions of the `AlamofireImage.framework` nested inside a `Products` folder.
107
 
108
    > It does not matter which `Products` folder you choose from, but it does matter whether you choose the top or bottom `AlamofireImage.framework`.
109
 
110
- Select the top `AlamofireImage.framework` for iOS and the bottom one for OS X.
111
 
112
    > You can verify which one you selected by inspecting the build log for your project. The build target for `AlamofireImage` will be listed as either `AlamofireImage iOS`, `AlamofireImage macOS`, `AlamofireImage tvOS` or `AlamofireImage watchOS`.
113
 
114
- And that's it!
115
 
116
  > The `AlamofireImage.framework` is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.
117
 
118
---
119
 
120
## Usage
121
 
122
### Image Response Serializers
123
 
124
```swift
125
import Alamofire
126
import AlamofireImage
127
 
128
Alamofire.request("https://httpbin.org/image/png").responseImage { response in
129
	debugPrint(response)
130
 
131
	print(response.request)
132
	print(response.response)
133
	debugPrint(response.result)
134
 
135
    if case .success(let image) = response.result {
136
		print("image downloaded: \(image)")
137
	}
138
}
139
```
140
 
141
The AlamofireImage response image serializers support a wide range of image types including:
142
 
143
 
144
- `image/png`
145
- `image/jpeg`
146
- `image/tiff`
147
- `image/gif`
148
- `image/ico`
149
- `image/x-icon`
150
- `image/bmp`
151
- `image/x-bmp`
152
- `image/x-xbitmap`
153
- `image/x-ms-bmp`
154
- `image/x-win-bitmap`
155
- `image/heic`
156
- `application/octet-stream` (added for iOS 13 support)
157
 
158
> If the image you are attempting to download is an invalid MIME type not in the list, you can add custom acceptable content types using the `addAcceptableImageContentTypes` extension on the `DataRequest` type.
159
 
160
### UIImage Extensions
161
 
162
There are several `UIImage` extensions designed to make the common image manipulation operations as simple as possible.
163
 
164
#### Inflation
165
 
166
```swift
167
let url = Bundle.main.url(forResource: "unicorn", withExtension: "png")!
168
let data = try! Data(contentsOf: url)
169
let image = UIImage(data: data, scale: UIScreen.main.scale)!
170
 
171
image.af.inflate()
172
```
173
 
174
> Inflating compressed image formats (such as PNG or JPEG) in a background queue can significantly improve drawing performance on the main thread.
175
 
176
#### Scaling
177
 
178
```swift
179
let image = UIImage(named: "unicorn")!
180
let size = CGSize(width: 100.0, height: 100.0)
181
 
182
// Scale image to size disregarding aspect ratio
183
let scaledImage = image.af.imageScaled(to: size)
184
 
185
// Scale image to fit within specified size while maintaining aspect ratio
186
let aspectScaledToFitImage = image.af.imageAspectScaled(toFit: size)
187
 
188
// Scale image to fill specified size while maintaining aspect ratio
189
let aspectScaledToFillImage = image.af.imageAspectScaled(toFill: size)
190
```
191
 
192
#### Rounded Corners
193
 
194
```swift
195
let image = UIImage(named: "unicorn")!
196
let radius: CGFloat = 20.0
197
 
198
let roundedImage = image.af.imageRounded(withCornerRadius: radius)
199
let circularImage = image.af.imageRoundedIntoCircle()
200
```
201
 
202
#### Core Image Filters
203
 
204
```swift
205
let image = UIImage(named: "unicorn")!
206
 
207
let sepiaImage = image.af.imageFiltered(withCoreImageFilter: "CISepiaTone")
208
 
209
let blurredImage = image.af.imageFiltered(
210
    withCoreImageFilter: "CIGaussianBlur",
211
    parameters: ["inputRadius": 25]
212
)
213
```
214
 
215
### Image Filters
216
 
217
The `ImageFilter` protocol was designed to make it easy to apply a filter operation and cache the result after an image finished downloading. It defines two properties to facilitate this functionality.
218
 
219
```swift
220
public protocol ImageFilter {
221
    var filter: Image -> Image { get }
222
    var identifier: String { get }
223
}
224
```
225
 
226
The `filter` closure contains the operation used to create a modified version of the specified image. The `identifier` property is a string used to uniquely identify the filter operation. This is useful when adding filtered versions of an image to a cache. All identifier properties inside AlamofireImage are implemented using protocol extensions.
227
 
228
#### Single Pass
229
 
230
The single pass image filters only perform a single operation on the specified image.
231
 
232
```swift
233
let image = UIImage(named: "unicorn")!
234
let imageFilter = RoundedCornersFilter(radius: 10.0)
235
 
236
let roundedImage = imageFilter.filter(image)
237
```
238
 
239
The current list of single pass image filters includes:
240
 
241
- `ScaledToSizeFilter` - Scales an image to a specified size.
242
- `AspectScaledToFitSizeFilter` - Scales an image from the center while maintaining the aspect ratio to fit within a specified size.
243
- `AspectScaledToFillSizeFilter` - Scales an image from the center while maintaining the aspect ratio to fill a specified size. Any pixels that fall outside the specified size are clipped.
244
- `RoundedCornersFilter` - Rounds the corners of an image to the specified radius.
245
- `CircleFilter` - Rounds the corners of an image into a circle.
246
- `BlurFilter` - Blurs an image using a `CIGaussianBlur` filter with the specified blur radius.
247
 
248
> Each image filter is built ontop of the `UIImage` extensions.
249
 
250
#### Multi-Pass
251
 
252
The multi-pass image filters perform multiple operations on the specified image.
253
 
254
```swift
255
let image = UIImage(named: "avatar")!
256
let size = CGSize(width: 100.0, height: 100.0)
257
let imageFilter = AspectScaledToFillSizeCircleFilter(size: size)
258
 
259
let avatarImage = imageFilter.filter(image)
260
```
261
 
262
The current list of multi-pass image filters includes:
263
 
264
- `ScaledToSizeWithRoundedCornersFilter` - Scales an image to a specified size, then rounds the corners to the specified radius.
265
- `AspectScaledToFillSizeWithRoundedCornersFilter` - Scales an image from the center while maintaining the aspect ratio to fit within a specified size, then rounds the corners to the specified radius.
266
- `ScaledToSizeCircleFilter` - Scales an image to a specified size, then rounds the corners into a circle.
267
- `AspectScaledToFillSizeCircleFilter` - Scales an image from the center while maintaining the aspect ratio to fit within a specified size, then rounds the corners into a circle.
268
 
269
### Image Cache
270
 
271
Image caching can become complicated when it comes to network images. `URLCache` is quite powerful and does a great job reasoning through the various cache policies and `Cache-Control` headers. However, it is not equipped to handle caching multiple modified versions of those images.
272
 
273
For example, let's say you need to download an album of images. Your app needs to display both the thumbnail version as well as the full size version at various times. Due to performance issues, you want to scale down the thumbnails to a reasonable size before rendering them on-screen. You also need to apply a global CoreImage filter to the full size images when displayed. While `URLCache` can easily handle storing the original downloaded image, it cannot store these different variants. What you really need is another caching layer designed to handle these different variants.
274
 
275
```swift
276
let imageCache = AutoPurgingImageCache(
277
    memoryCapacity: 100_000_000,
278
    preferredMemoryUsageAfterPurge: 60_000_000
279
)
280
```
281
 
282
The `AutoPurgingImageCache` in AlamofireImage fills the role of that additional caching layer. It is an in-memory image cache used to store images up to a given memory capacity. When the memory capacity is reached, the image cache is sorted by last access date, then the oldest image is continuously purged until the preferred memory usage after purge is met. Each time an image is accessed through the cache, the internal access date of the image is updated.
283
 
284
#### Add / Remove / Fetch Images
285
 
286
Interacting with the `ImageCache` protocol APIs is very straightforward.
287
 
288
```swift
289
let imageCache = AutoPurgingImageCache()
290
let avatarImage = UIImage(data: data)!
291
 
292
// Add
293
imageCache.add(avatarImage, withIdentifier: "avatar")
294
 
295
// Fetch
296
let cachedAvatar = imageCache.image(withIdentifier: "avatar")
297
 
298
// Remove
299
imageCache.removeImage(withIdentifier: "avatar")
300
```
301
 
302
#### URL Requests
303
 
304
The `ImageRequestCache` protocol extends the `ImageCache` protocol by adding support for `URLRequest` caching. This allows a `URLRequest` and an additional identifier to generate the unique identifier for the image in the cache.
305
 
306
```swift
307
let imageCache = AutoPurgingImageCache()
308
 
309
let urlRequest = URLRequest(url: URL(string: "https://httpbin.org/image/png")!)
310
let avatarImage = UIImage(named: "avatar")!.af.imageRoundedIntoCircle()
311
 
312
// Add
313
imageCache.add(avatarImage, for: urlRequest, withIdentifier: "circle")
314
 
315
// Fetch
316
let cachedAvatarImage = imageCache.image(for: urlRequest, withIdentifier: "circle")
317
 
318
// Remove
319
imageCache.removeImage(for: urlRequest, withIdentifier: "circle")
320
```
321
 
322
#### Auto-Purging
323
 
324
Each time an image is fetched from the cache, the cache internally updates the last access date for that image.
325
 
326
```swift
327
let avatar = imageCache.image(withIdentifier: "avatar")
328
let circularAvatar = imageCache.image(for: urlRequest, withIdentifier: "circle")
329
```
330
 
331
By updating the last access date for each image, the image cache can make more informed decisions about which images to purge when the memory capacity is reached. The `AutoPurgingImageCache` automatically evicts images from the cache in order from oldest last access date to newest until the memory capacity drops below the `preferredMemoryCapacityAfterPurge`.
332
 
333
> It is important to set reasonable default values for the `memoryCapacity` and `preferredMemoryCapacityAfterPurge` when you are initializing your image cache. By default, the `memoryCapacity` equals 100 MB and the `preferredMemoryCapacityAfterPurge` equals 60 MB.
334
 
335
#### Memory Warnings
336
 
337
The `AutoPurgingImageCache` also listens for memory warnings from your application and will purge all images from the cache if a memory warning is observed.
338
 
339
### Image Downloader
340
 
341
The `ImageDownloader` class is responsible for downloading images in parallel on a prioritized queue. It uses an internal Alamofire `SessionManager` instance to handle all the downloading and response image serialization. By default, the initialization of an `ImageDownloader` uses a default `URLSessionConfiguration` with the most common parameter values.
342
 
343
```swift
344
let imageDownloader = ImageDownloader(
345
    configuration: ImageDownloader.defaultURLSessionConfiguration(),
346
    downloadPrioritization: .fifo,
347
    maximumActiveDownloads: 4,
348
    imageCache: AutoPurgingImageCache()
349
)
350
```
351
 
352
> If you need to customize the `URLSessionConfiguration` type or parameters, then simply provide your own rather than using the default.
353
 
354
#### Downloading an Image
355
 
356
```swift
357
let downloader = ImageDownloader()
358
let urlRequest = URLRequest(url: URL(string: "https://httpbin.org/image/jpeg")!)
359
 
360
downloader.download(urlRequest) { response in
361
    print(response.request)
362
    print(response.response)
363
    debugPrint(response.result)
364
 
365
    if case .success(let image) = response.result {
366
        print(image)
367
    }
368
}
369
```
370
 
371
> Make sure to keep a strong reference to the `ImageDownloader` instance, otherwise the `completion` closure will not be called because the `downloader` reference will go out of scope before the `completion` closure can be called.
372
 
373
#### Applying an ImageFilter
374
 
375
```swift
376
let downloader = ImageDownloader()
377
let urlRequest = URLRequest(url: URL(string: "https://httpbin.org/image/jpeg")!)
378
let filter = AspectScaledToFillSizeCircleFilter(size: CGSize(width: 100.0, height: 100.0))
379
 
380
downloader.download(urlRequest, filter: filter) { response in
381
    print(response.request)
382
    print(response.response)
383
    debugPrint(response.result)
384
 
385
    if case .success(let image) = response.result {
386
        print(image)
387
    }
388
}
389
```
390
 
391
#### Authentication
392
 
393
If your images are behind HTTP Basic Auth, you can append the `user:password:` or the `credential` to the `ImageDownloader` instance. The credentials will be applied to all future download requests.
394
 
395
```swift
396
let downloader = ImageDownloader()
397
downloader.addAuthentication(user: "username", password: "password")
398
```
399
 
400
#### Download Prioritization
401
 
402
The `ImageDownloader` maintains an internal queue of pending download requests. Depending on your situation, you may want incoming downloads to be inserted at the front or the back of the queue. The `DownloadPrioritization` enumeration allows you to specify which behavior you would prefer.
403
 
404
```swift
405
public enum DownloadPrioritization {
406
    case fifo, lifo
407
}
408
```
409
 
410
> The `ImageDownloader` is initialized with a `.fifo` queue by default.
411
 
412
#### Image Caching
413
 
414
The `ImageDownloader` uses a combination of an `URLCache` and `AutoPurgingImageCache` to create a very robust, high performance image caching system.
415
 
416
##### URLCache
417
 
418
The `URLCache` is used to cache all the original image content downloaded from the server. By default, it is initialized with a memory capacity of 20 MB and a disk capacity of 150 MB. This allows up to 150 MB of original image data to be stored on disk at any given time. While these defaults have been carefully set, it is very important to consider your application's needs and performance requirements and whether these values are right for you.
419
 
420
> If you wish to disable this caching layer, create a custom `URLSessionConfiguration` with the `urlCache` property set to `nil` and use that configuration when initializing the `ImageDownloader`.
421
 
422
##### Image Cache
423
 
424
The `ImageCache` is used to cache all the potentially filtered image content after it has been downloaded from the server. This allows multiple variants of the same image to also be cached, rather than having to re-apply the image filters to the original image each time it is required. By default, an `AutoPurgingImageCache` is initialized with a memory capacity of 100 MB and a preferred memory usage after purge limit of 60 MB. This allows up to 100 MB of most recently accessed filtered image content to be stored in-memory at a given time.
425
 
426
##### Setting Ideal Capacity Limits
427
 
428
Determining the ideal the in-memory and on-disk capacity limits of the `URLCache` and `AutoPurgingImageCache` requires a bit of forethought. You must carefully consider your application's needs, and tailor the limits accordingly. By default, the combination of caches offers the following storage capacities:
429
 
430
- 150 MB of on-disk storage (original image only)
431
- 20 MB of in-memory original image data storage (original image only)
432
- 100 MB of in-memory storage of filtered image content (filtered image if using filters, otherwise original image)
433
- 60 MB preferred memory capacity after purge of filtered image content
434
 
435
> If you do not use image filters, it is advised to set the memory capacity of the `URLCache` to zero. Otherwise, you will be storing the original image data in both the URLCache's in-memory store as well as the AlamofireImage in-memory store.
436
 
437
#### Duplicate Downloads
438
 
439
Sometimes application logic can end up attempting to download an image more than once before the initial download request is complete. Most often, this results in the image being downloaded more than once. AlamofireImage handles this case elegantly by merging the duplicate downloads. The image will only be downloaded once, yet both completion handlers will be called.
440
 
441
##### Image Filter Reuse
442
 
443
In addition to merging duplicate downloads, AlamofireImage can also merge duplicate image filters. If two image filters with the same identifier are attached to the same download, the image filter is only executed once and both completion handlers are called with the same resulting image. This can save large amounts of time and resources for computationally expensive filters such as ones leveraging CoreImage.
444
 
445
##### Request Receipts
446
 
447
Sometimes it is necessary to cancel an image download for various reasons. AlamofireImage can intelligently handle cancellation logic in the `ImageDownloader` by leveraging the `RequestReceipt` type along with the `cancelRequestForRequestReceipt` method. Each download request vends a `RequestReceipt` which can be later used to cancel the request.
448
 
449
By cancelling the request through the `ImageDownloader` using the `RequestReceipt`, AlamofireImage is able to determine how to best handle the cancellation. The cancelled download will always receive a cancellation error, while duplicate downloads are allowed to complete. If the download is already active, it is allowed to complete even though the completion handler will be called with a cancellation error. This greatly improves performance of table and collection views displaying large amounts of images.
450
 
451
> It is NOT recommended to directly call `cancel` on the `request` in the `RequestReceipt`. Doing so can lead to issues such as duplicate downloads never being allowed to complete.
452
 
453
### UIImageView Extension
454
 
455
The [UIImage Extensions](#uiimage-extensions), [Image Filters](#image-filters), [Image Cache](#image-cache) and [Image Downloader](#image-downloader) were all designed to be flexible and standalone, yet also to provide the foundation of the `UIImageView` extension. Due to the powerful support of these classes, protocols and extensions, the `UIImageView` APIs are concise, easy to use and contain a large amount of functionality.
456
 
457
#### Setting Image with URL
458
 
459
Setting the image with a URL will asynchronously download the image and set it once the request is finished.
460
 
461
```swift
462
let imageView = UIImageView(frame: frame)
463
let url = URL(string: "https://httpbin.org/image/png")!
464
 
465
imageView.af.setImage(withURL: url)
466
```
467
 
468
> If the image is cached locally, the image is set immediately.
469
 
470
#### Placeholder Images
471
 
472
By specifying a placeholder image, the image view uses the placeholder image until the remote image is downloaded.
473
 
474
```swift
475
let imageView = UIImageView(frame: frame)
476
let url = URL(string: "https://httpbin.org/image/png")!
477
let placeholderImage = UIImage(named: "placeholder")!
478
 
479
imageView.af.setImage(withURL: url, placeholderImage: placeholderImage)
480
```
481
 
482
> If the remote image is cached locally, the placeholder image is never set.
483
 
484
#### Image Filters
485
 
486
If an image filter is specified, it is applied asynchronously after the remote image is downloaded. Once the filter execution is complete, the resulting image is set on the image view.
487
 
488
```swift
489
let imageView = UIImageView(frame: frame)
490
 
491
let url = URL(string: "https://httpbin.org/image/png")!
492
let placeholderImage = UIImage(named: "placeholder")!
493
 
494
let filter = AspectScaledToFillSizeWithRoundedCornersFilter(
495
    size: imageView.frame.size,
496
    radius: 20.0
497
)
498
 
499
imageView.af.setImage(
500
    withURL: url,
501
    placeholderImage: placeholderImage,
502
    filter: filter
503
)
504
```
505
 
506
> If the remote image with the applied filter is cached locally, the image is set immediately.
507
 
508
#### Image Transitions
509
 
510
By default, there is no image transition animation when setting the image on the image view. If you wish to add a cross dissolve or flip-from-bottom animation, then specify an `ImageTransition` with the preferred duration.
511
 
512
```swift
513
let imageView = UIImageView(frame: frame)
514
 
515
let url = URL(string: "https://httpbin.org/image/png")!
516
let placeholderImage = UIImage(named: "placeholder")!
517
 
518
let filter = AspectScaledToFillSizeWithRoundedCornersFilter(
519
    size: imageView.frame.size,
520
    radius: 20.0
521
)
522
 
523
imageView.af.setImage(
524
    withURL: url,
525
    placeholderImage: placeholderImage,
526
    filter: filter,
527
    imageTransition: .crossDissolve(0.2)
528
)
529
```
530
 
531
> If the remote image is cached locally, the image transition is ignored.
532
 
533
#### Image Downloader
534
 
535
The `UIImageView` extension is powered by the default `ImageDownloader` instance. To customize cache capacities, download priorities, request cache policies, timeout durations, etc., please refer to the [Image Downloader](#image-downloader) documentation.
536
 
537
##### Authentication
538
 
539
If an image requires and authentication credential from the `UIImageView` extension, it can be provided as follows:
540
 
541
```swift
542
ImageDownloader.default.addAuthentication(user: "user", password: "password")
543
```
544
 
545
---
546
 
547
## Credits
548
 
549
Alamofire is owned and maintained by the [Alamofire Software Foundation](http://alamofire.org). You can follow them on Twitter at [@AlamofireSF](https://twitter.com/AlamofireSF) for project updates and releases.
550
 
551
### Security Disclosure
552
 
553
If you believe you have identified a security vulnerability with AlamofireImage, you should report it as soon as possible via email to security@alamofire.org. Please do not post it to a public issue tracker.
554
 
555
## Donations
556
 
557
The [ASF](https://github.com/Alamofire/Foundation#members) is looking to raise money to officially stay registered as a federal non-profit organization.
558
Registering will allow us members to gain some legal protections and also allow us to put donations to use, tax free.
559
Donating to the ASF will enable us to:
560
 
561
- Pay our yearly legal fees to keep the non-profit in good status
562
- Pay for our mail servers to help us stay on top of all questions and security issues
563
- Potentially fund test servers to make it easier for us to test the edge cases
564
- Potentially fund developers to work on one of our projects full-time
565
 
566
The community adoption of the ASF libraries has been amazing.
567
We are greatly humbled by your enthusiasm around the projects, and want to continue to do everything we can to move the needle forward.
568
With your continued support, the ASF will be able to improve its reach and also provide better legal safety for the core members.
569
If you use any of our libraries for work, see if your employers would be interested in donating.
570
Any amount you can donate today to help us reach our goal would be greatly appreciated.
571
 
572
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W34WPEE74APJQ)
573
 
574
## License
575
 
576
AlamofireImage is released under the MIT license. [See LICENSE](https://github.com/Alamofire/AlamofireImage/blob/master/LICENSE) for details.