Member-only story

Get class name as string in Swift

--

Photo by Abdelrahman Sobhy on Unsplash

What’s the Problem?

Sometimes you need to define the identifier same as the class name. Then you define a constant string same as class name which is not coupled with original class name. If someone changed the class name then it’ll not change and exception will occur. To resolve this problem, best coding practice is to use the string from class itself.

Solution:

Here is a protocol by which you can access the name in string directly from class. Here is the example:

Thank You! Happy coding! 👍

Enjoy my previous articles!

--

--

No responses yet