Search code examples
swiftaclaccess-controlinternal

When I use internal access control level explicitly in Swift 4


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?


Solution

  • 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.