I have a question about internal access control level
Internal
is default
access control level in Swift
so I think all of internal
access control should be removed
Is there a specific case of using internal
access control explicitly in Swift?
When or How I use internal
access control in Swift?
I found a case internal
needs to be added explicitly:
public internal(set) var myInt = 0
Omitting the internal
keyword results in a compile error.
This is particular useful in a swift package/pod. The property is exposed publicly, but only inside the package/pod, the value can be changed.
As per documentation:
Default Access Levels All entities in your code (with a few specific exceptions, as described later in this chapter) have a default access level of internal if you don’t specify an explicit access level yourself. As a result, in many cases you don’t need to specify an explicit access level in your code.
Source: https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html
As you mentioned, using the "internal" keyword has no effect other than making it clear that a function should never be made public in the future without careful consideration. At this point using the "internal" keyword is more about documenting and commenting your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With