Junior — Middle
Milliseid juurdepääsu modifikaatoreid teate ja kuidas need töötavad?
sobes.tech AI
Vastus AI-lt
In iOS (Swift), there are three main access modifiers that regulate the visibility and access to properties and methods:
public— accessible from any module and file.internal— accessible within the current module (default).fileprivate— accessible only within the current file.private— accessible only within the current declaration (e.g., class or struct).
Example:
class Example {
private var secret = "secret"
fileprivate func fileFunc() {}
internal func internalFunc() {}
public func publicFunc() {}
}
private restricts access to secret only within the Example class. fileprivate allows using fileFunc anywhere in the current file. internal is available throughout the module, and public everywhere, including other modules.