@@ -10,7 +10,7 @@ import Foundation
1010import UIKit
1111
1212public protocol ImageAsset : RawRepresentable where RawValue == String {
13- /// The bundle containing the image assets (default is `.main`)
13+ /// The bundle containing the image assets for this enum (default is `.main`)
1414 static var bundle : Bundle { get }
1515
1616 /// Optional namespace for the image assets (default is `nil`).
@@ -31,12 +31,24 @@ public protocol ImageAsset: RawRepresentable where RawValue == String {
3131}
3232
3333extension ImageAsset {
34- /// The bundle containing the image assets (default is `.main`)
34+ /// The bundle containing the image assets for this enum (default is `.main`)
3535 public static var bundle : Bundle { . main }
3636
3737 /// Optional namespace for the image assets (default is `nil`)
3838 public static var namespace : String ? { nil }
3939
40+ /// fallback image to use in case an image asset cannot be loaded (default is `.systemPink`)
41+ public static var fallbackImage : UIImage {
42+ let renderer = UIGraphicsImageRenderer ( size: CGSize ( width: 16 , height: 16 ) )
43+ let image = renderer. image { ctx in
44+ let rectangle = CGRect ( x: 0 , y: 0 , width: 16 , height: 16 )
45+ ctx. cgContext. setFillColor ( UIColor . systemPink. cgColor)
46+ ctx. cgContext. addRect ( rectangle)
47+ ctx. cgContext. drawPath ( using: . fill)
48+ }
49+ return image
50+ }
51+
4052 /// Loads the named image
4153 ///
4254 /// Default implementation uses `UIImage(named:in:compatibleWith:)` passing in the associated `namespace`
0 commit comments