Today we’ll quickly explore the difference between the public and openkeywords in Swift.

In short, we use open when we’re working on a module that at some point will be imported in a different module and overridden.

For example, when you’re developing your own reusable UI element and want to distribute it using CocoaPods, you may consider using the openkeyword to let others override the behavior of your library. With public, you may simply import the framework, but you can’t override it.

Without a further ado, let’s get started.


Let’s Start

Say we’re creating our own UI element, and we want it to be reusable and independent. So we create a new target in our existing project, like so:

Image for post

Next, we choose Static Library in the drop-down:

Image for post

#mobile #xcode #ios #swift #programming

What’s the Difference Between Public and Open in Swift?
11.15 GEEK