存取控制最重要的兩個分野為 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 Control
Jerry Wang ⟩ Access Control 教學
SwiftLee ⟩ fileprivate vs private in Swift: The differences explained
What's the difference of private and fileprivate class in the same file in Swift?
private
fileprivate
Last updated 3 years ago
Was this helpful?