Ever since Swift's release, marking a class public endows that class with these two capabilities:

  • it allows other modules to instantiate and use that class
  • it allows other modules to create subclasses from it

Similarly, marking a class' member public gives that member two capabilities:

  • it allows other modules to use that member
  • it allows other modules to override that member

Refinement

But now with Swift 3, classes get something extra. A new access level is introduced that offloads some of public's permissive capabilities and adopts it unto itself. It's called open.

open

A very important detail, open can only be used on classes and a class's overridable members. So this doesn't concern structs and enums whatsoever.

Class and member

An open class will both be

  • usable (by other modules) and
  • subclassable

As a result, a public class can now only be usable (by other modules) but not be subclassable anymore.

An open member will both be

  • usable (by other modules) and
  • overridable

This also results in a public member to be now only usable (by other modules) but not overridable anymore.

Open members

• A member that overrides its superclass' member is invalid if that member is declared outside of the current module AND the access level of that member is not open

• A member that is open and is inherited from a superclass is still considered open in the subclass unless the class is final

Example