9
9
import Foundation
10
10
import UIKit
11
11
12
- /// Any named image asset can be loaded from an asset catalog
12
+ /// Any named image asset can be loaded from an asset catalog.
13
13
///
14
14
/// All properties and functions have default implementations. At a minimum just have your string-based enum conform
15
15
/// 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 {
22
22
/// Optional namespace for the image assets (default is `nil`).
23
23
static var namespace : String ? { get }
24
24
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`)
26
27
static var fallbackImage : UIImage { get }
27
28
28
29
/// An image asset for this name value.
@@ -32,7 +33,7 @@ public protocol ImageAsset: RawRepresentable where RawValue == String {
32
33
33
34
/// Loads the image.
34
35
///
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.
36
37
func loadImage( ) -> UIImage ?
37
38
}
38
39
@@ -43,23 +44,22 @@ extension ImageAsset {
43
44
/// Optional namespace for the image assets (default is `nil`)
44
45
public static var namespace : String ? { nil }
45
46
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`)
47
49
public static var fallbackImage : UIImage {
48
50
let renderer = UIGraphicsImageRenderer ( size: CGSize ( width: 16 , height: 16 ) )
49
51
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) )
54
54
}
55
55
return image
56
56
}
57
57
58
- /// Loads the named image
58
+ /// Loads the named image.
59
59
///
60
60
/// Default implementation uses `UIImage(named:in:compatibleWith:)` passing in the associated `namespace`
61
61
/// (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.
63
63
public func loadImage( ) -> UIImage ? {
64
64
let name : String
65
65
if let validNamespace = Self . namespace {
0 commit comments