onevcat 8 лет назад
Родитель
Сommit
6a09ddda3e
1 измененных файлов с 21 добавлено и 0 удалено
  1. 21 0
      Sources/Placeholder.swift

+ 21 - 0
Sources/Placeholder.swift

@@ -30,19 +30,39 @@
     import UIKit
     import UIKit
 #endif
 #endif
 
 
+
+/// Represent a placeholder type which could be set while loading as well as
+/// loading finished without getting an image.
 public protocol Placeholder {
 public protocol Placeholder {
+    
+    /// How the placeholder should be added to a given image view.
     func add(to imageView: ImageView)
     func add(to imageView: ImageView)
+    
+    /// How the placeholder should be removed from a given image view.
     func remove(from imageView: ImageView)
     func remove(from imageView: ImageView)
 }
 }
 
 
+/// Default implementation of an image placeholder. The image will be set or 
+/// reset directly for `image` property of the image view.
 extension Placeholder where Self: Image {
 extension Placeholder where Self: Image {
+    
+    /// How the placeholder should be added to a given image view.
     public func add(to imageView: ImageView) { imageView.image = self }
     public func add(to imageView: ImageView) { imageView.image = self }
+    
+    /// How the placeholder should be removed from a given image view.
     public func remove(from imageView: ImageView) { imageView.image = nil }
     public func remove(from imageView: ImageView) { imageView.image = nil }
 }
 }
 
 
 extension Image: Placeholder {}
 extension Image: Placeholder {}
 
 
+/// Default implementation of an arbitrary view as placeholder. The view will be 
+/// added as a subview when adding and be removed from its super view when removing.
+///
+/// To use your customize View type as placeholder, simply let it conforming to 
+/// `Placeholder` by `extension MyView: Placeholder {}`.
 extension Placeholder where Self: View {
 extension Placeholder where Self: View {
+    
+    /// How the placeholder should be added to a given image view.
     public func add(to imageView: ImageView) {
     public func add(to imageView: ImageView) {
         imageView.addSubview(self)
         imageView.addSubview(self)
 
 
@@ -55,6 +75,7 @@ extension Placeholder where Self: View {
             ])
             ])
     }
     }
 
 
+    /// How the placeholder should be removed from a given image view.
     public func remove(from imageView: ImageView) {
     public func remove(from imageView: ImageView) {
         self.removeFromSuperview()
         self.removeFromSuperview()
     }
     }