Use Public Access Control in Swift
Written by Team Kodeco
Written by Team Kodeco
In Swift, the public access control level is the most permissive level of access control.
Public access allows a type or type member (e.g. property, method, initializer) to be accessed from any module or library. This means that any code, whether it’s within the same module or a different module, can access and use the public type or type member.
Here’s an example of a public class in Swift:
public class MyPublicClass {
public var myPublicProperty = "I am a public property"
public func myPublicMethod() {
print("I am a public method")
}
}
In this example, the MyPublicClass
and its myPublicProperty
and myPublicMethod
are public and can be accessed and used by any code in any module.
Prev chapter
4.
Use Internal Access Control in Swift
Next chapter
1.
Define Swift Closures