When you write a class in Swift, by default any of these properties, methods can be accessed externally. Sometimes we don't want the property or method to be externally accessible and want to privatize. There are three keywords in swift: Public access, which allows any source file to use its definition module. If you use Xctest to test a class, you need to add public before the class. Internal:swift default access control, allowing access within the project. Private: Personal access, accessible only in the current class. If it is added before class, it is only the current file access. To illustrate: public class Somepublicclass {//Explicit public class
public var somepublicproperty = 0//Explicit public class member
var someinternalproperty = 0//default internal class member
Private Func Someprivatemethod () {}//explicit private class member
}
Class Someinternalclass {//Default internal class
var someinternalproperty = 0//default internal class member
Private Func Someprivatemethod () {}//explicit private class member
}
Private class Someprivateclass {//explicit private class
var someprivateproperty = 0//default private class member
Func Someprivatemethod () {}//default private class member
}
Swift-access control