0

While reading someone else's Swift 3 code I came across a private function declared in at the head of a file. By this I mean it is not enclosed in a instancetype. My understanding is that:

Private access restricts the use of an entity to the enclosing declaration

But what is the enclosing declaration here? The module, and if so how does this differ from the default internal? Xcode's intelligence does not seem to "see" this function in other files, so I assume enclosing declaration is not the module.

So as far as I can tell the enclosing declaration is the file itself (which seems odd).

So my questions is, What is the enclosing declaration in this case? And If it is the file how does this differ from fileprivate in this case, and If it is the module how does it differ from internal in this case?

The file is structured as follows:

import Foundation 
import otherStuff

private typealias Bar = (new: [Foo], changed: [Foo])

private func fooBar(){
//stuff
}

private func foo() {
// more stuff
}

private final class Bar {
// a hole bunch of stuff 
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
TMin
  • 2,280
  • 1
  • 25
  • 34
  • 1
    Same question here: https://stackoverflow.com/questions/39739813/private-vs-fileprivate-on-declaring-global-variables-consts-in-swift3. – Martin R Sep 18 '17 at 19:39
  • In this case the enclosing scope is the global scope so it isn't a class or instance method, but the function is private, so it is only accessible in that file. See also https://stackoverflow.com/questions/42939690/how-is-a-global-variable-set-to-private-understood-in-swift – Paulw11 Sep 18 '17 at 19:42

0 Answers0