I have a Swift Package in my SwiftUI project that includes styles for UI components. Also, this package includes a resource folder that contains assets that can be used in styling. I can get an image by its name but I would like to know if I could access images with enums. Because Xcode 15 automatically generates symbols for assets.
The following example would explain what I mean:
public struct CheckboxToggleStyle: ToggleStyle {
@Binding var color: Color
let checked = Image("checkbox-checked", bundle: .module) // ✅ works
let unchecked = Image("checkbox-unchecked", bundle: .module) // ✅ works
let checked = Image(.checkboxChecked) // ❌ failed
let unchecked = Image(.checkboxUnchecked) // ❌ failed
public func makeBody(configuration: Configuration) -> some View {
(configuration.isOn ? checked : unchecked)
.renderingMode(.template)
.foregroundColor(color)
.onTapGesture {
withAnimation {
configuration.isOn.toggle()
}
}
}
}