moko-resources
moko-resources copied to clipboard
Class name ImageResource collides with Xcode generated ImageResource
In a KMP project, moko's ImageResource class name collides silently with Xcode generated ImageResource struct (from GeneratedAssetSymbols.swift).
The issue arises when trying to use an asset from the asset catalog in a SwiftUI component. For example, let's say you have an asset named "record". Xcode will generate this:
@available(iOS 11.0, macOS 10.7, tvOS 11.0, *)
extension ImageResource {
/// The "record" asset catalog image resource.
static let record = ImageResource(name: "record", bundle: resourceBundle)
}
But trying to access it in a SwiftUI component that accepts an "ImageResource", like
Toggle(LocalizedStringKey, image: ImageResource, isOn: Binding<Bool>)
will first raise this error for the placeholders:
Cannot convert value of type 'shared.ImageResource' to expected argument type 'DeveloperToolsSupport.ImageResource'
Then, trying to put the generated ImageResource as such:
Toggle("some value", image: .record, isOn: .constant(true))
will fail with the error Type 'ImageResource' has no member 'record'.
Even trying to extract the variable like this:
let theResource: ImageResource = .record
Toggle("some value", image: theResource, isOn: .constant(true))
fails with the same Cannot convert value of type 'shared.ImageResource' to expected argument type 'DeveloperToolsSupport.ImageResource' error.
I was thinking, moko's ImageResource class name could be customisable, or maybe even have it be different from the start. What do you reckon?