I'm trying to get the system name of a SF Symbol. Here is my image:
let image = UIImage(systemName: "checkmark.circle.fill")
How can I get the system name of that image later?
I also found out that when I print the description of the image, it prints the symbol name along with other data. Is there a way I could extract the name from there?
<UIImage:0x600001d50900 symbol(system: checkmark.circle.fill) {20, 19} baseline=3.5,contentInsets={1, 1.5, 1, 1.5},alignmentRectInsets={-0.5, 0, -0.5, 0} config=<(null), traits=(UserInterfaceIdiom = Pad, DisplayScale = 2, DisplayGamut = P3, HorizontalSizeClass = Regular, VerticalSizeClass = Regular, UserInterfaceStyle = Light, UserInterfaceLayoutDirection = LTR, PreferredContentSizeCategory = L, AccessibilityContrast = Normal)>>
There isn't a way to get images used in an UIImage instance, But a workaround would be setting the "accessibilityIdentifier" so it can be used later.
let img = UIImage(named: "Cat")
img?.accessibilityIdentifier = "Cat"
print(img?.accessibilityIdentifier) // Outputs: Cat
More from: How to get Image Name used in an UIImage?