Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add apple only Mapper<NSURL, Url> and Mapper<NSURL, File> #71

Open
luca992 opened this issue Nov 12, 2023 · 12 comments
Open

Add apple only Mapper<NSURL, Url> and Mapper<NSURL, File> #71

luca992 opened this issue Nov 12, 2023 · 12 comments

Comments

@luca992
Copy link
Member

luca992 commented Nov 12, 2023

Support multiple mappers per input class type #70 Is required for this.

Ideally these would be offered in the default config: #69

@iruizmar
Copy link
Contributor

🤔 There's a problem here. KClass for Objective-C classes is not supported yet. That means we can't use NSURL on Mapper as it relies on passing the KClass:

image

Any workaround?

@iruizmar
Copy link
Contributor

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.

@luca992
Copy link
Member Author

luca992 commented Nov 12, 2023

🤔 There's a problem here. KClass for Objective-C classes is not supported yet. That means we can't use NSURL on Mapper as it relies on passing the KClass:

image

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

@iruizmar
Copy link
Contributor

iruizmar commented Nov 13, 2023

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.

@luca992
Copy link
Member Author

luca992 commented Nov 13, 2023

@iruizmar check here I did this in like 15 minutes... it's a mess but works:

#74

I'd really rather try and find another way if possible. But lmk what you think

@luca992
Copy link
Member Author

luca992 commented Nov 13, 2023

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

@iruizmar
Copy link
Contributor

I like more the second approach, yeah. Delegating everything to Strings looks odd. Do you want me to pull the thread from there?

@luca992
Copy link
Member Author

luca992 commented Nov 13, 2023

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.

@iruizmar
Copy link
Contributor

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?

@luca992
Copy link
Member Author

luca992 commented Nov 13, 2023

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

@luca992
Copy link
Member Author

luca992 commented Nov 13, 2023

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

@iruizmar
Copy link
Contributor

Sorry mate, I have a peak of work this week. Maybe during the weekend, I will be able to take a look! 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants