Add apple only Mapper<NSURL, Url> and Mapper<NSURL, File>
luca992 opened this issue · comments
I think the only possible workaround is to create a Kotlin object wrapper around NSURL as it's done when using Koin. But the API will be way worse.
🤔 There's a problem here. KClass for Objective-C classes is not supported yet. That means we can't use
NSURL
onMapper
as it relies on passing theKClass
:![]()
Any workaround?
Hmmm can you get any sort of class name out of it as a string?... Or maybe is it possible to declare a companion object on it? If so just maybe it's possible to check if it has a companion object kclass as a backup if that error gets thrown
This works:
println("${NSURL.`class`()}")
and the output is "NSURL". Can you elaborate on how can we use this with the mappers?
This is OK, btw:
assertEquals(NSURL.`class`(), NSURL.fileURLWithPath(path).`class`())
Meaning we can compare it with an instance type.
Maybe something like this could be used as the mappers key:
sealed interface CommonClass
internal value class KClassWrapped<T : Any>(private val kclass: KClass<T>) : CommonClass
internal value class ObjCClassWrapped(private val objcClass: ObjCClass) : CommonClass
Then maybe it's possible to do something like this:
![Screenshot 2023-11-13 at 4 54 31 AM](https://private-user-images.githubusercontent.com/4157455/282425583-70921263-aeec-4911-9657-0029ddfe2b5b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTM5NDA2NTYsIm5iZiI6MTcxMzk0MDM1NiwicGF0aCI6Ii80MTU3NDU1LzI4MjQyNTU4My03MDkyMTI2My1hZWVjLTQ5MTEtOTY1Ny0wMDI5ZGRmZTJiNWIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDQyNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA0MjRUMDYzMjM2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9N2FhZTI1MGFhZTVkNmIyYWJjYmYzZjdhMzhjNmQyNjU3ZDM2NzBjYmY3OWFjNzJkODJjNjA3MDY3MGVkNTdhMSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.MgaT4fNkCKB0w_eKKGQNCi23knLV2UfK2Pp5w4uLlqc)
I like more the second approach, yeah. Delegating everything to Strings looks odd. Do you want me to pull the thread from there?
I like more the second approach, yeah. Delegating everything to Strings looks odd. Do you want me to pull the thread from there?
yeah probably don't pull that. I just made that pr to show you more easily.
We can continue with the CommonClass
approach, then, if you like it. I can make a quick draft and we can work on the final API from there. WDYT?
We can continue with the
CommonClass
approach, then, if you like it. I can make a quick draft and we can work on the final API from there. WDYT?
sounds good to me if you have the motivation to do it 👍. Otherwise I can try and get to it in the next couple weeks
Also I'm not positive the CommonClass
won't have problems. But that's just what I'm thinking might work.
A method or extension to convert Any
to a CommonClass
will have to be an expect actual I think... either that or I guess ObjCClassWrapped could be an expect actual that is only defined for apple targets... The first approach probably makes more sense however
Sorry mate, I have a peak of work this week. Maybe during the weekend, I will be able to take a look! 👍🏻