Avatar ·

What does the `open` keyword mean in Swift and how is it different from `public`?

Hi everyone! I recently started learning Swift and got confused about access modifiers. In the documentation I read about `public`, `internal`, `fileprivate`, and `private`, but then I came across `open`. \n\nI understand that `public` makes a class or method accessible from another module. But why is `open` needed then? Doesn't `public` do the same thing? \n\nHere's an example: I created my own framework and want users to not only use my class but also inherit from it. If I set `public`, the class will be visible, but the compiler won't allow inheriting from it. If I set `open` — inheritance is allowed. Why is that?\n\nAlso, I'm confused that `open` can only be applied to classes and class members. And for structs and protocols, as I understand, `open` is not used. Is that true?