Junior — Middle
What is the role of access modifiers in controlling access to class members?
sobes.tech AI
Answer from AI
Access modifiers in iOS (Swift) control the visibility and access to class members (properties and methods). The main modifiers are private, fileprivate, internal (default), public, and open.
privaterestricts access only within the current class or struct.fileprivateallows access to all elements within the same file.internalpermits access within the module (application or framework).publicandopenallow access from other modules, withopenenabling inheritance and overriding outside the module.
This helps encapsulate data, protect the internal state of an object, and control which parts of the API are accessible to external code.