can we declare public property in internal class or struct
Generated on 8/7/2024
1 search
Yes, you can declare a public property in an internal class or struct in Swift. The access control levels in Swift allow for this kind of declaration.
From the session A Swift Tour: Explore Swift’s features and design, it is mentioned that:
"Public is one of several different access control levels available in Swift. There are also private, internal, and package levels. A declaration that is marked private can only be accessed by code in the same file. An internal declaration can only be accessed by other code in the same module. Whenever you don't specify an access level, Swift implicitly uses internal package declarations are accessible from other modules in the same package, and public declarations are accessible from any other module."
This means that you can have an internal class or struct with public properties, making those properties accessible from any other module, while the class or struct itself remains accessible only within the same module.
Explore Swift performance
Discover how Swift balances abstraction and performance. Learn what elements of performance to consider and how the Swift optimizer affects them. Explore the different features of Swift and how they’re implemented to further understand the tradeoffs available that can impact performance.
A Swift Tour: Explore Swift’s features and design
Learn the essential features and design philosophy of the Swift programming language. We’ll explore how to model data, handle errors, use protocols, write concurrent code, and more while building up a Swift package that has a library, an HTTP server, and a command line client. Whether you’re just beginning your Swift journey or have been with us from the start, this talk will help you get the most out of the language.
Migrate your app to Swift 6
Experience Swift 6 migration in action as we update an existing sample app. Learn how to migrate incrementally, module by module, and how the compiler helps you identify code that’s at risk of data races. Discover different techniques for ensuring clear isolation boundaries and eliminating concurrent access to shared mutable state.