if I have a property
@property (nonatomic, retain) NSArray* myArray;
Can I do ? And if yes why does this work ?
for (id object in self.myArray)
;
Or do I need to do ?
NSArray* r = self.myArray;
for (id object in r)
;
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.
It works because self.myArray is syntactical sugar for [self myArray], which is generated by the @synthesize keyword. So really you’re doing:
And the return value of [self myArray] implements the fast enumeration protocol so the for..in syntax can work on it.
Does that make things clearer?