I have been going through the recent swift docs and working out on few examples in understanding private and fileprivate keywords in swift4. I am trying to access a fileprivate and private variable in an extension of the same class and another class subclassing the class but the output is unfruitful. I'm using in the following way
class privateUsageExample: UIViewController {
private var priVar = false
fileprivate var fPriVar = false
}
// usage of extension in the same class
extension privateUsageExample: UITextFieldDelegate {
if priVar{ // do something} // error : expected declaration
if fPriVar{ // do something} // error : expected declaration
func randFunc(){
self. fPriVar = true // accessible don't know the reason
}
}
// access of private and fileprivate variables in another class different file
class anotherUsageInDiffSwiftFile: privateUsageExample {
priVar = false // inaccessible (how to access it)
fPriVar = true // inaccessible (how to access it)
}
can you please help me out in accessing priVar (private) and fPriVar (fileprivate) variable in the extension of the same class in the same file and in another class subclassing the class in the different file.