Hello. Is there best practics for returns platform...
# multiplatform
r
Hello. Is there best practics for returns platform Type from
expect
function? For example,
Drawable
for android and
UIImage
for ios?
g
You need some abstraction for that that wraps both of those types. like
Image
which itself maybe expect declaration, implemented on each platform in a way that exposes platform type
i
typealias?
g
Typealias may work, but you will have no common methods in this case, so it will be a type which may be references, but doesn't have any methods to use from common code. Imo real wrapper is more flexible, even of you don't have any common methods yet
a
Yes, this not for use inside common code, but for some type of declaration of intent. If we go deeper into this example, imagine what we want to declare some abstract API. Method that receive image ID and returns image resource. For android it will be
fun getImageForId(id:Int):Drawable
For iOS
fun getImageForId(id:NSString):UIImage
Of course I can declare those funcs separately, but it will be nice to declare abstract contract for
getImageForId
inside common code.
g
Both typealias or real wrapper approach will work in this case. You can even abstract image id param