My class has some @properties (strong); apples, bananas and oranges of NSArray* type; and I’m wondering if this:
for(NSArray* __strong fruit in @[apples, bananas, oranges]) {
fruit = [fruit sortedArrayUsingComparator:comparator];
}
is the same as this:
apples = [apples sortedArrayUsingComparator:comparator];
bananas = [bananas sortedArrayUsingComparator:comparator];
oranges = [oranges sortedArrayUsingComparator:comparator];
comparator is an NSComparator.
I think they should be the same but I’m not sure how the __strong relates to the for loop in this context.
this is not the same code, the loop will not change the values of the variables
apples,bananasandorangesin your loop you assigning the sort-result to the local variable
fruit, this will not affect the contents of the values stored inapples,bananasororanges.in the ‘unrolled’ code you assigning the sort-result to the original variables, therefore overwriting the content of this variables.
Also i think your loop-type
Fruitis wrong, unlessapples,bananasandorangesare of typeFruitand not of typeNSArraywhich the rest of the code suggests.