[swift-users] private vs. fileprivate on global declaration in Swift3?

davelist at mac.com davelist at mac.com
Wed Sep 28 09:29:58 CDT 2016


> On Sep 28, 2016, at 3:22 AM, Cao Jiannan via swift-users <swift-users at swift.org> wrote:
> 
> Should I use private or fileprivate to declare global variables/consts in Swift 3? e.g.
> 
> fileprivate let a = 1
> fileprivate class SomeClass {
>     fileprivate b = 0
> }
> 
> or
> 
> private let a = 1
> private class SomeClass {
>     fileprivate b = 0
> }
> 
> Thanks!
> 
> If they are identity, then I think the Swift team should tell us which is better.

They aren't identical. Here's a good explanation:

http://useyourloaf.com/blog/swift-3-access-controls/

HTH,
Dave Reed



More information about the swift-users mailing list