diff --git a/Source/iOS/Extensions/UIImage+RenderingMode.swift b/Source/iOS/Extensions/UIImage+RenderingMode.swift index 4a2eba8..2f82bf0 100644 --- a/Source/iOS/Extensions/UIImage+RenderingMode.swift +++ b/Source/iOS/Extensions/UIImage+RenderingMode.swift @@ -2,11 +2,19 @@ import UIKit public extension UIImage { - public var original: UIImage { + public var original: UIImage? { + guard hasContent else { + return nil + } + return withRenderingMode(.alwaysOriginal) } - public var template: UIImage { + public var template: UIImage? { + guard hasContent else { + return nil + } + return withRenderingMode(.alwaysTemplate) } } diff --git a/Tests/iOS/TestUIImage.swift b/Tests/iOS/TestUIImage.swift index 0569f24..2840ff9 100644 --- a/Tests/iOS/TestUIImage.swift +++ b/Tests/iOS/TestUIImage.swift @@ -8,4 +8,8 @@ class UIImageTests: XCTestCase { XCTAssertEqual(UIImage().hasContent, false) XCTAssertEqual(UIImage(color: UIColor.red).hasContent, true) } + + func testContent() { + XCTAssertNil(UIImage().template) + } }