存取控制最重要的兩個分野為 module 和 source file:
module:一個 bundle ID 下的 app 或一個 framework。
source file:就是每一個 .swift 檔案。
分 5 個層級,最高到最低依次為:
open / public / internal / file-private / private
The only reason you would use fileprivate is when you want to access your code within the same file from different classes or structs. 👉 SwfitLee
// fileprivate setter fileprivate(set) var a = 1
extensions have to be defined within the same file, private declarations are not visible outside the file.
Swift ⟩ Access Controlarrow-up-right
Jerry Wang ⟩ Access Control 教學arrow-up-right
SwiftLee ⟩ fileprivate vs private in Swift: The differences explainedarrow-up-right
What's the difference of private and fileprivate class in the same file in Swift?arrow-up-right
private
fileprivate
Last updated 3 years ago