Swift UIKit: How to register and dequeue reusable cells in more elegant way. Introducing Powerful Extension

No matter what programming language you use, you should avoid hardcoded values. It’s a bad process that can make bugs very easily. Literal Strings are the worst of all kinds. You can waste your precious time because of tiny typo mistakes.

Common Problem

Common Approach

If you are using UIKit, you probably have seen this code. Since you are a true developer, you will feel uncomfortable as soon as you see “MyCell”. It looks like legitimate code, and in fact it’s likely not causing any major problems. But there’s a better way, I’ll show you.

Better Approach with Generic

Better Approach

It’s by convention to use the same file name with the same reuse identifier. With that in mind, using Generic and String(describing: type), which returns Class Name, you can use this extension to write more robust code.


  • Avoid Hard Coded Values
  • Use extensions I just introduced!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
KD Knowledge Diet

Software Engineer, Mobile Developer living in Seoul. I hate people using difficult words. Why not using simple words? Keep It Simple Stupid!