Skip to content

Commit

Permalink
Final code cleanup and polish.
Browse files Browse the repository at this point in the history
  • Loading branch information
kiavashfaisali committed Oct 3, 2016
1 parent 794e5ff commit 1dcb97e
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 56 deletions.
6 changes: 3 additions & 3 deletions Example/KFSwiftImageLoader/UI/Base.lproj/Main.storyboard
Expand Up @@ -27,7 +27,7 @@
<frame key="frameInset" width="375" height="187"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="60y-FW-Ju1"/>
<imageView opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="60y-FW-Ju1" userLabel="Featured Image"/>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="60y-FW-Ju1" secondAttribute="bottom" id="4pE-UM-BNM"/>
Expand All @@ -47,7 +47,7 @@
<frame key="frameInset" width="375" height="187"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="center" adjustsImageWhenHighlighted="NO" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="z7R-wX-Uvl" userLabel="Button Image"/>
<button opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="center" adjustsImageWhenHighlighted="NO" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="z7R-wX-Uvl" userLabel="Featured Button"/>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="z7R-wX-Uvl" secondAttribute="bottom" id="2bt-O9-ZuO"/>
Expand All @@ -57,7 +57,7 @@
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="featuredButtonView" destination="z7R-wX-Uvl" id="IV0-NZ-aT8"/>
<outlet property="featuredButton" destination="z7R-wX-Uvl" id="m9B-86-dOx"/>
</connections>
</tableViewCell>
</prototypes>
Expand Down
Expand Up @@ -116,7 +116,7 @@ extension MainViewController: UITableViewDataSource {

// Notice that the completion closure can be ommitted, since it defaults to nil. The `controlState` and `isBackgroundImage` parameters can also be ommitted, as they default to `.normal` and `false`, respectively.
// Please read the documentation for more information.
cell.featuredButtonView.loadImage(urlString: self.imageURLStringsArray[indexPath.row], placeholderImage: UIImage(named: "KiavashFaisali"), forState: .normal, isBackgroundImage: false)
cell.featuredButton.loadImage(urlString: self.imageURLStringsArray[indexPath.row], placeholderImage: UIImage(named: "KiavashFaisali"), controlState: .normal, isBackgroundImage: false)

return cell
}
Expand Down
Expand Up @@ -7,12 +7,12 @@ import UIKit

final class ButtonImageTableViewCell: UITableViewCell {
// MARK: - Properties
@IBOutlet weak var featuredButtonView: UIButton!
@IBOutlet weak var featuredButton: UIButton!

// MARK: - View Recycling
override func prepareForReuse() {
self.featuredButtonView.setImage(nil, for: UIControlState())
self.featuredButtonView.setBackgroundImage(nil, for: UIControlState())
self.featuredButton.setImage(nil, for: UIControlState())
self.featuredButton.setBackgroundImage(nil, for: UIControlState())

super.prepareForReuse()
}
Expand Down
12 changes: 6 additions & 6 deletions KFSwiftImageLoader/Classes/MKAnnotationViewExtensions.swift
Expand Up @@ -30,8 +30,8 @@ public extension MKAnnotationView {
- parameter completion: An optional closure that is called to indicate completion of the intended purpose of this method. It returns two values: the first is a `Bool` indicating whether everything was successful, and the second is `NSError?` which will be non-nil should an error occur. The default value is `nil`.
*/
final public func loadImage(urlString: String,
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
{
guard let url = URL(string: urlString) else {
DispatchQueue.main.async {
Expand All @@ -52,8 +52,8 @@ public extension MKAnnotationView {
- parameter completion: An optional closure that is called to indicate completion of the intended purpose of this method. It returns two values: the first is a `Bool` indicating whether everything was successful, and the second is `NSError?` which will be non-nil should an error occur. The default value is `nil`.
*/
final public func loadImage(url: URL,
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
{
let cacheManager = KFImageCacheManager.sharedInstance

Expand All @@ -71,8 +71,8 @@ public extension MKAnnotationView {
- parameter completion: An optional closure that is called to indicate completion of the intended purpose of this method. It returns two values: the first is a `Bool` indicating whether everything was successful, and the second is `NSError?` which will be non-nil should an error occur. The default value is `nil`.
*/
final public func loadImage(request: URLRequest,
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
{
self.completionHolder = CompletionHolder(completion: completion)

Expand Down
28 changes: 14 additions & 14 deletions KFSwiftImageLoader/Classes/UIButtonExtensions.swift
Expand Up @@ -61,10 +61,10 @@ public extension UIButton {
- parameter completion: An optional closure that is called to indicate completion of the intended purpose of this method. It returns two values: the first is a `Bool` indicating whether everything was successful, and the second is `NSError?` which will be non-nil should an error occur. The default value is `nil`.
*/
final public func loadImage(urlString: String,
placeholderImage: UIImage? = nil,
forState controlState: UIControlState = .normal,
isBackgroundImage: Bool = false,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
placeholderImage: UIImage? = nil,
controlState: UIControlState = .normal,
isBackgroundImage: Bool = false,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
{
guard let url = URL(string: urlString) else {
DispatchQueue.main.async {
Expand All @@ -74,7 +74,7 @@ public extension UIButton {
return
}

loadImage(url: url, placeholderImage: placeholderImage, forState: controlState, isBackgroundImage: isBackgroundImage, completion: completion)
loadImage(url: url, placeholderImage: placeholderImage, controlState: controlState, isBackgroundImage: isBackgroundImage, completion: completion)
}

/**
Expand All @@ -87,17 +87,17 @@ public extension UIButton {
- parameter completion: An optional closure that is called to indicate completion of the intended purpose of this method. It returns two values: the first is a `Bool` indicating whether everything was successful, and the second is `NSError?` which will be non-nil should an error occur. The default value is `nil`.
*/
final public func loadImage(url: URL,
placeholderImage: UIImage? = nil,
forState controlState: UIControlState = .normal,
isBackgroundImage: Bool = false,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
placeholderImage: UIImage? = nil,
controlState: UIControlState = .normal,
isBackgroundImage: Bool = false,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
{
let cacheManager = KFImageCacheManager.sharedInstance

var request = URLRequest(url: url, cachePolicy: cacheManager.session.configuration.requestCachePolicy, timeoutInterval: cacheManager.session.configuration.timeoutIntervalForRequest)
request.addValue("image/*", forHTTPHeaderField: "Accept")

loadImage(request: request, placeholderImage: placeholderImage, forState: controlState, isBackgroundImage: isBackgroundImage, completion: completion)
loadImage(request: request, placeholderImage: placeholderImage, controlState: controlState, isBackgroundImage: isBackgroundImage, completion: completion)
}

/**
Expand All @@ -110,10 +110,10 @@ public extension UIButton {
- parameter completion: An optional closure that is called to indicate completion of the intended purpose of this method. It returns two values: the first is a `Bool` indicating whether everything was successful, and the second is `NSError?` which will be non-nil should an error occur. The default value is `nil`.
*/
final public func loadImage(request: URLRequest,
placeholderImage: UIImage? = nil,
forState controlState: UIControlState = UIControlState(),
isBackgroundImage: Bool = false,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
placeholderImage: UIImage? = nil,
controlState: UIControlState = UIControlState(),
isBackgroundImage: Bool = false,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
{
self.completionHolder = CompletionHolder(completion: completion)
self.indexPathIdentifier = -1
Expand Down
12 changes: 6 additions & 6 deletions KFSwiftImageLoader/Classes/UIImageViewExtensions.swift
Expand Up @@ -39,8 +39,8 @@ public extension UIImageView {
- parameter completion: An optional closure that is called to indicate completion of the intended purpose of this method. It returns two values: the first is a `Bool` indicating whether everything was successful, and the second is `NSError?` which will be non-nil should an error occur. The default value is `nil`.
*/
final public func loadImage(urlString: String,
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
{
guard let url = URL(string: urlString) else {
DispatchQueue.main.async {
Expand All @@ -61,8 +61,8 @@ public extension UIImageView {
- parameter completion: An optional closure that is called to indicate completion of the intended purpose of this method. It returns two values: the first is a `Bool` indicating whether everything was successful, and the second is `NSError?` which will be non-nil should an error occur. The default value is `nil`.
*/
final public func loadImage(url: URL,
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
{
let cacheManager = KFImageCacheManager.sharedInstance

Expand All @@ -80,8 +80,8 @@ public extension UIImageView {
- parameter completion: An optional closure that is called to indicate completion of the intended purpose of this method. It returns two values: the first is a `Bool` indicating whether everything was successful, and the second is `NSError?` which will be non-nil should an error occur. The default value is `nil`.
*/
final public func loadImage(request: URLRequest,
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
{
self.completionHolder = CompletionHolder(completion: completion)
self.indexPathIdentifier = -1
Expand Down
18 changes: 9 additions & 9 deletions KFSwiftImageLoader/Classes/WKInterfaceImageExtensions.swift
Expand Up @@ -61,9 +61,9 @@ public extension WKInterfaceImage {
- parameter completion: An optional closure that is called to indicate completion of the intended purpose of this method. It returns two values: the first is a `Bool` indicating whether everything was successful, and the second is `NSError?` which will be non-nil should an error occur. The default value is `nil`.
*/
final public func loadImage(urlString: String,
placeholderImageName: String? = nil,
shouldUseDeviceCache: Bool = false,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
placeholderImageName: String? = nil,
shouldUseDeviceCache: Bool = false,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
{
guard let url = URL(string: urlString) else {
DispatchQueue.main.async {
Expand All @@ -85,9 +85,9 @@ public extension WKInterfaceImage {
- parameter completion: An optional closure that is called to indicate completion of the intended purpose of this method. It returns two values: the first is a `Bool` indicating whether everything was successful, and the second is `NSError?` which will be non-nil should an error occur. The default value is `nil`.
*/
final public func loadImage(url: URL,
placeholderImageName: String? = nil,
shouldUseDeviceCache: Bool = false,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
placeholderImageName: String? = nil,
shouldUseDeviceCache: Bool = false,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
{
let cacheManager = KFImageCacheManager.sharedInstance

Expand All @@ -106,9 +106,9 @@ public extension WKInterfaceImage {
- parameter completion: An optional closure that is called to indicate completion of the intended purpose of this method. It returns two values: the first is a `Bool` indicating whether everything was successful, and the second is `NSError?` which will be non-nil should an error occur. The default value is `nil`.
*/
final public func loadImage(request: URLRequest,
placeholderImageName: String? = nil,
shouldUseDeviceCache: Bool = false,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
placeholderImageName: String? = nil,
shouldUseDeviceCache: Bool = false,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
{
self.completionHolder = CompletionHolder(completion: completion)

Expand Down
28 changes: 14 additions & 14 deletions README.md
Expand Up @@ -63,17 +63,17 @@ imageView.loadImage(urlString: urlString, placeholderImage: UIImage(named: "Kiav
For flexibility, there are several different methods for loading images.
Below are the method signatures for all of them:
``` swift
func loadImage(urlString urlString: String,
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
func loadImage(urlString: String,
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)

func loadImage(url url: URL,
func loadImage(url: URL,
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)

func loadImage(request: URLRequest,
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)

func loadImage(request request: URLRequest,
placeholderImage: UIImage? = nil,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
```

### WKInterfaceImage
Expand All @@ -100,14 +100,14 @@ Again, KFSwiftImageLoader makes it very easy to load images.
In this case, the button uses mostly the same method signature as UIImageView, but it includes two more optional parameters: "isBackgroundImage" and "forState".

``` swift
func loadImage(urlString urlString: String,
placeholderImage: UIImage? = nil,
forState controlState: UIControlState = .normal,
isBackgroundImage: Bool = false,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
func loadImage(urlString: String,
placeholderImage: UIImage? = nil,
controlState: UIControlState = .normal,
isBackgroundImage: Bool = false,
completion: ((_ success: Bool, _ error: NSError?) -> Void)? = nil)
```

"forState" takes a UIControlState value that is required when setting images for buttons.
"controlState" takes a UIControlState value that is required when setting images for buttons.
"isBackgroundImage" simply indicates whether or not the button should use "setBackgroundImage:for:" or "setImage:for:" for image loading.

### MKAnnotationView
Expand Down

0 comments on commit 1dcb97e

Please sign in to comment.