Suppose I have something like this:
@property (readonly) NSMutableArray *someArray;
Can I modify [obj someArray] even though the @property is set to readonly?
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.
Yes, you can modify its contents. The readonly only applies to the pointer itself – in that way, it is not like C++’s
const.Basically, saying ‘readonly’ just means ‘don’t translate
a.someArray = foointo[a setSomeArray:foo]‘. That is, no setter is created.(Of course, if you wanted to prevent modification, you’d just use an
NSArrayinstead.)