I just discovered this and thought I would share it. Look at this code:
It turns out it is file based. If you are in the same file as the class you can access the private variables. But if you put your class in one file and then instantiate it another file then you cannot access the private variables.
class Vehicle { private var color: String = "red" } var car = Vehicle() print(car.color)
How am I able to access the color property even though it is private?
It turns out it is file based. If you are in the same file as the class you can access the private variables. But if you put your class in one file and then instantiate it another file then you cannot access the private variables.
(Swift 2.2)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.