Ah, metatypes. That’s another one for the list of things I use everyday but couldn’t explain in an interview if my life depended on it.

Metatypes are pretty useful in Swift, and you have certainly used it on multiple occasions. Unfortunately they look pretty weird in code, which can cause some confusion when trying to understand what they really are.

I know how these weird suffixes can confuse you, but don’t worry, they’re actually pretty straightforward once you get to know the differences between each of them. But before getting into that, let’s take a step back.

What’s a Metatype?

If you take a look at Apple’s docs, you’ll see that a metatype is defined as being the type of a type. Wait, isn’t String a type? What could possibly be type of a String that’s already a type? SuperString??

#swift #xcode #ios #.protocol #.type #.self

What Are .self, .Type, and .Protocol?
2.45 GEEK