Porting an init function in a protocol extension produces errors

Hullo, I wanted to turn a class in a struct and move intelligence in a protocol extension, but when I try to call inits in the extension I get

'self' used before 'self.init' call or assignment to 'self'

How do I call self.init or assign to self before updating the values? Of course init does no accept mutating.

I wanted to turn a class in a struct and move intelligence in a protocol extension

Why?

There's a lot of pressure for developers to use static typing practices like using structs instead of classes. But a dirty little secret is that Swift is a great object-oriented language.

How do I call self.init or assign to self before updating the values?

You don't have self until you call init. Despite my previous statement about Swift, it does have its quirks. In object-oriented Swift, you must initialize instance values before calling super.init, which is actually backwards. (There are "reasons" for this, but rather than making those edge cases a developer responsibility, they built it into the language. Because Swift is safe by default, except when it isn't.)

But if you're writing an extension on a struct, then it's more logical. You must construct the object before you can use it.

Porting an init function in a protocol extension produces errors
 
 
Q