99import Foundation
1010import UIKit
1111
12- /// Any named image asset can be loaded from an asset catalog
12+ /// Any named image asset can be loaded from an asset catalog.
1313///
1414/// All properties and functions have default implementations. At a minimum just have your string-based enum conform
1515/// to `ImageAsset` (and have an asset catalog with matching assets). If your enum and assets live inside a Swift
@@ -22,7 +22,8 @@ public protocol ImageAsset: RawRepresentable where RawValue == String {
2222 /// Optional namespace for the image assets (default is `nil`).
2323 static var namespace : String ? { get }
2424
25- /// Fallback image to use in case an image asset cannot be loaded (default is `.systemPink`)
25+ /// Fallback image to use in case an image asset cannot be loaded.
26+ /// (default is a 16 x 16 square filled with `.systemPink`)
2627 static var fallbackImage : UIImage { get }
2728
2829 /// An image asset for this name value.
@@ -32,7 +33,7 @@ public protocol ImageAsset: RawRepresentable where RawValue == String {
3233
3334 /// Loads the image.
3435 ///
35- /// - Returns: The named image or else `nil`,If the named asset cannot be loaded.
36+ /// - Returns: The named image or else `nil` if the named asset cannot be loaded.
3637 func loadImage( ) -> UIImage ?
3738}
3839
@@ -43,23 +44,22 @@ extension ImageAsset {
4344 /// Optional namespace for the image assets (default is `nil`)
4445 public static var namespace : String ? { nil }
4546
46- /// fallback image to use in case an image asset cannot be loaded (default is `.systemPink`)
47+ /// Fallback image to use in case an image asset cannot be loaded.
48+ /// (default is a 16 x 16 square filled with `.systemPink`)
4749 public static var fallbackImage : UIImage {
4850 let renderer = UIGraphicsImageRenderer ( size: CGSize ( width: 16 , height: 16 ) )
4951 let image = renderer. image { ctx in
50- let rectangle = CGRect ( x: 0 , y: 0 , width: 16 , height: 16 )
51- ctx. cgContext. setFillColor ( UIColor . systemPink. cgColor)
52- ctx. cgContext. addRect ( rectangle)
53- ctx. cgContext. drawPath ( using: . fill)
52+ UIColor . systemPink. setFill ( )
53+ ctx. fill ( CGRect ( origin: . zero, size: renderer. format. bounds. size) )
5454 }
5555 return image
5656 }
5757
58- /// Loads the named image
58+ /// Loads the named image.
5959 ///
6060 /// Default implementation uses `UIImage(named:in:compatibleWith:)` passing in the associated `namespace`
6161 /// (prepended to `rawValue`) and `bundle`.
62- /// - Returns: The named image or else `nil` if the named asset cannot be loaded
62+ /// - Returns: The named image or else `nil` if the named asset cannot be loaded.
6363 public func loadImage( ) -> UIImage ? {
6464 let name : String
6565 if let validNamespace = Self . namespace {
0 commit comments