In case you have not noticed, there is no straight forward alternative to using 'instanceType' in Swift. You might have tried using "Self" in place of instanceType like shown in the below code snippet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
But turns out it gives an error saying the object cannot be converted to type Self. I found this elegant solution posted by Martin R on StackOverflow and it uses Generics.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'm pretty excited about this new feature in Swift; Generics. This is something borrowed from C++. The `Swift Programming Language` bo...
About Me
Adithya
iOS app developer by profession, Internet addict, Blogger, Tech enthusiast, Gadget freak especially smartphones, Amateur photographer, Music lover, Cricket fan.
0 comments:
Post a Comment