Aggressor Aggressor - 7 months ago 51
Swift Question

Attribute 'public' can only be used in a non-local scope

A very technical error here and Google turned up nothing on this.

I am adding Cordova to a Swift Project.

I added a Bridging Header file and the Cordova build dependencies, and I did get autocomplete working (the Cordva CDV classes were auto-completing).

Everything was working fine until I suddenly got this error:

Attribute 'public' can only be used in a non-local scope


And my project just lit up with errors everywhere. Also tons of my functions stopped working.

enter image description here

Any suggestions as to what happened or what I could do to fix would be much appreciated

Answer

That error shows up when you have public declared on a type that is nested inside a function or method—types declared in that context have only local scope, and thus can't be marked as public. Example:

func foo() {
    public struct Bar {        
    }
}
// Attribute 'public' can only be used in a non-local scope
Comments