The code below is legal in Swift, however, I was just wondering why class Something
is not forced to be declared private. The reason why I'm saying that is because one of its variable, private var anInstanceOfWhatever: Whatever = Whatever()
, is a private variable, if class Something
is declared internal
or public
, I can use class Something outside the source file, but one of its variable can only be accessed within the source file, doesn't it create an conflict of some sort? Could someone please help me clarify the concept?
private class Whatever{
}
class Something{
private var anInstanceOfWhatever: Whatever = Whatever()
var number: Int = 0
var text: String = ""
}
No, it does not create a conflict. If you used Something
outside of the file, you simply wouldn't be able to access the property anInstanceOfWhatever
, but you could access every non-private property or method.