Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift Basics (retired) Control Flow For-In Loop

if the FOR - IN loop implicitly uses a constant, could it be used in anyway to modify the value of each element?

//Pseudo-code for item in Array { if item meets certain criteria then modify it }

1 Answer

Ravee Sundar
PLUS
Ravee Sundar
Courses Plus Student 1,975 Points

If the Array is Mutable, you can check a condition and modify it by using the following

[myMutableArray replaceObjectAtIndex:index withObject:newObject];

Please refer the following URL for more details:

http://stackoverflow.com/questions/3064122/how-to-replace-an-object-in-an-nsmutablearray-at-a-given-index-with-a-new-object