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