Declaration is only valid at file scope (extension)

The error message is quite clear. You cannot declare an extension inside of anything – inside a class declaration, inside a struct declaration, etc. It must be outside of everything, at the top level of the containing file. There must be no curly braces around it. You have not shown the context in which you are declaring this extension, but clearly there are curly … Read more