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

What is nesting and why do we use it

Hi I'm doing swift and wanted to know what nesting is used for .

Thanks

1 Answer

Hey jon kelson,

Your question is very vague because nesting can refer to a lot of different things. You can have nested types, nested functions, nested dictionaries...

It all comes down to scope and encapsulation. Sometimes it doesn't make sense to expose information to other parts of the code that will never need access to it. For example, a function thats only ever used inside of another function. If the rest of the code doesn't need to know about it, then don't let it access it.

Good Luck

Ok thanks Steven . Sorry about the vagueness . I saw some code, that was a Dictionary and also an array , they mentioned nesting but didn't say what it meant .

Many thanks Jon