Deborah Elizabeth Padilla Deborah Elizabeth Padilla - 1 month ago 21
Swift Question

Swift / How to use extensions

I have tried to declare an extension for a class, but I'm receiving erros. What am I missing? Help is very appreciated.

Screenshot

Answer

As it says. Extensions aren't allowed to store properties. Just declare var somePoint = (1, 1) in the main Class. Not within the Extension.

You have stored it like this

extension AFErorr...... {
   var somePoint = (1, 1)
}

But you need to put it inside the Class itself.

class AFErorr...... {
   var somePoint = (1, 1)
}

Switch somePoint is declared outside of the Class. That is the 2nd error. You need to declare it within the Class. And then the 3rd error should be gone as well.

class AFErorr...... {
   switch somePoint.... {
   }
}