Are there access modifiers in Swift? (public, private, internal)
Hello everyone! I just started learning Swift, coming from Java and C++, and I have one question bothering me. In Java, I'm used to explicitly specifying `public`, `private`, `protected` before every class, method, or field. But in Swift, I see that in code examples they often don't write anything before the declaration, and it still works. For example:
```swift
class MyClass {
var name = "John"
func sayHello() {
print("Hello")
}
}
```
And I can access this class and its methods from another file in the same project. Does this mean that by default everything is `public`? Or is there some other default modifier? And how do I make something completely hidden inside a file or inside a class? I've heard about `fileprivate` and `open`, but I don't understand when to use them. Please explain what access modifiers exist in Swift, what their default is, and how they differ from Java.
No answers yet.
Log in to leave an answer