Page 237

Swift Enumeration in Swift language automatically receive the same access level for individual cases of an enumeration. Consider for example to access the students name and marks secured in three subjects enumeration name is declared as student and the members present in enum class are name which belongs to string datatype, marks are represented as mark1, mark2 and mark3 of datatype Integer. To access either the student name or marks they have scored. Now, the switch case will print student name if that case block is executed otherwise it will print the marks secured by the student. If both condition fails the default block will be executed.

Access Control for SubClasses Swift allows the user to subclass any class that can be accessed in the current access context. A subclass cannot have a higher access level than its superclass. The user is restricted from writing a public subclass of an internal superclass. public class cricket { private func print() { println("Welcome to Swift Super Class") } }

internal class tennis: cricket


override internal func print() { println("Welcome to Swift Sub Class") } }

let cricinstance = cricket() cricinstance.print()

let tennisinstance = tennis() tennisinstance.print() When we run the above program using playground, we get the following result: Welcome to Swift Super Class Welcome to Swift Sub Class

Access Control for Constants, variables, properties and subscripts Swift constant, variable, or property cannot be defined as public than its type. It is not valid to write a public property with a private type. Similarly, a subscript cannot be more public than its index or return type. 225

​Quick is a effective and user-friendly coding language for macOS, iOS, watchOS and tvOS....  


Read more
Read more
Similar to
Popular now
Just for you