Created
December 23, 2021 12:08
-
-
Save krzyzanowskim/d1194b4536f93cb97f04c55595037267 to your computer and use it in GitHub Desktop.
Image system and custom SFSymbol initializer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
extension Image { | |
init(symbol name: String, accessibilityDescription: String? = nil) { | |
if let nsImage = NSImage(systemSymbolName: name, accessibilityDescription: accessibilityDescription) { | |
self.init(nsImage: nsImage) | |
} else if let nsImage = NSImage(named: name) { | |
nsImage.accessibilityDescription = accessibilityDescription | |
self.init(nsImage: nsImage) | |
} else { | |
self.init(systemName: "") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment