Closed atticus183 closed 2 years ago
so, as we see this forcecast required, but maybe we can generate some comment for Xcode to ignore this warning?
just like in Kotlin we have @Suppress
https://developer.apple.com/forums/thread/18911?answerId=59439022#59439022 this answer maybe help
Hi @Alex009! I'm also working on the project with @atticus183 where we are running into the issue described in #46. We have looked into lots of ways to get around the warnings that Xcode is showing us and we weren't able to find a solution that we liked. The main issue is that both #pragma
commands and compiler flags (for specific files) are not supported by the Swift compiler, so we aren't able to ignore the warnings in the moko-kswift generated file.
With that in mind I took a look at the sealed class
to Swift enum
feature in kswift to see if I could come up with a solution that would allow generics to be force-cast when needed while not utilizing a force-cast when it is not necessary. I think I found a solution that I am happy with, but I am curious to hear what you think!
I added additional logic to the .sealed
property generation that uses a regex pattern to perform some additional checks to determine if a force-cast is necessary. The logic I added amounts to the following rules:
I also added some additional tests for both non-generic and generic sealed class
es to make sure that the logic I added works correctly.
This PR was created to eliminate the following Xcode warning:
Update
It looks like my proposed fix of replacing
as!
withas
breaks the sample app 😞. My apologies. This replacement seemed to resolve the issue with the project I'm on, but it may not be the way forward for everyone.