I have this code:
let sheet = UnsafeTGAPointer(SHEET_TGA)
.flatten(into: Image.self)
.grid(itemWidth: 16, itemHeight: 16)
but flatten
errors with "Cannot use metatype of type 'Image' in embedded Swift"
This is flatten:
public extension Drawable {
/// Shorthand for flattening a nested structure of lazy drawables into a trivial image, for
/// cases where using memory and losing information is preferable to repeatedly recomputing all layers.
///
/// This method is a convenience and overloads the generic version of this function in cases where
/// an explicit type is not provided, since an `Image` is the most primitive of drawables.
/// It is the equivalent of calling `flatten(into: Image.self)`.
@_disfavoredOverload func flatten() -> Image { .init(self) }
/// Shorthand for flattening a nested structure of lazy drawables into a primitive drawable, for
/// cases where using memory and losing information is preferable to repeatedly recomputing all layers.
///
/// This overload allows specifying the type in the middle of a method chain.
func flatten<T>(into type: T.Type) -> T where T: PrimitiveDrawable { .init(self) }
/// Shorthand for flattening a nested structure of lazy drawables into a primitive drawable, for
/// cases where using memory and losing information is preferable to repeatedly recomputing all layers.
///
/// This overload is used when inferring the return type.
func flatten<T>() -> T where T: PrimitiveDrawable { .init(self) }
}
There's the other two overloads, one that defaults to Image
and one that infers it from the return type, but neither is possible in a longer chain of methods, or even the simple one shown in the beginning of my post.
In this case I wanted to flatten into an image anyway, which has the default disfavored overload, but if I needed something else there's nothing I can do because methods can't be specialized.
Can I work around this somehow or is my only option to wait for Embedded Swift to improve this?