Quantcast
Viewing latest article 5
Browse Latest Browse All 6

Answer by Martin R for What is the 'open' keyword in Swift?

open is a new access level in Swift 3, introduced with the implementationof

It is available with the Swift 3 snapshot from August 7, 2016, and with Xcode 8 beta 6.

In short:

  • An open class is accessible and subclassable outside of thedefining module. An open class member is accessible andoverridable outside of the defining module.
  • A public class is accessible but not subclassable outside of thedefining module. A public class member is accessible butnot overridable outside of the defining module.

So open is what public used to be in previousSwift releases and the access of public has been restricted.Or, as Chris Lattner puts it in SE-0177: Allow distinguishing between public access and public overridability:

“open” is now simply “more public than public”, providing a very simple and clean model.

In your example, open var hashValue is a property which is accessible and can be overridden in NSObject subclasses.

For more examples and details, have a look at SE-0117.


Viewing latest article 5
Browse Latest Browse All 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>