subin272
subin272

Reputation: 753

What is the significance of filePrivate now in Swift 4?

Since now "Private" can be accessed within an extension what is the significance of "file private". Can anyone explain with an example.

Upvotes: 6

Views: 1332

Answers (1)

Rob
Rob

Reputation: 437702

private limits access to that class within that file. fileprivate limits access to that file.

Imagine these are all in the same file:

class Foo {
    private var x = 0
    fileprivate var y = 0
}

extension Foo {
    func bar() {
        // can access both x and y
    }
}

class Baz {
    func qux() {
        let foo = Foo()

        // can access foo.y, but not foo.x
    }
}

Upvotes: 13

Related Questions