I have a private variable in a class and I am trying to access that variable from an external class.
Is there a way I could do this?
I have a private variable in a class and I am trying to access
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The private instance variables are, by definition, private. You cannot access them externally. If you are the author of the class, you should provide accessor methods for the variable. If you’re not, you should refrain from accessing the variable.
However, there are ways to circumvent that limitation.
You may create a category on the first class and add an accessor method for the instance variable.
Or your may use Key-Value Coding to access the variable.