Strongly typed collection cells

Photo by Christopher Gower / Unsplash

Do you ever feel that using Strings as identifiers is not ideal? Losing track of names in storyboards, constants, view controllers, and data sources? We all have been there.

There is a solution to this problem. With the small help of protocols and default protocol implementation, UIKit can be strongly typed and convenient!

As a first step, introduce protocol and our contract:

This simple code will give us the foundation for the feature. Next step - logic!

We have to somehow automagically "generate" reuse identifiers for our cells in the whole project. Our best bet is cells class name. Every class has a unique name, can't be repeated. This uniqueness is key to our success.

That's it! Now every cell in the code has its own, automatically generated, always accessible, never confusing unique cell identifier.

Stay tuned, we will add some features to further simplify working with cells!

Artur Gruchała

Artur Gruchała

I started learning iOS development when Swift was introduced. Since then I've tried Xamarin, Flutter, and React Native. Nothing is better than native code:)
Poland