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 trialMark Nair
3,405 PointsHow do you add to an array within a struct data model?
I'm following along with the Fun Facts project in the Simple iPhone App lesson. I understand grabbing the random item from the array that is in the struct, and I understand the separate data model. But what if I wanted to add something to that array, such as a new fun fact? I'm struggling with how to append to the array because I'm using an instance of the struct (if that makes any sense).
1 Answer
kjvswift93
13,515 PointsWhy not simply add the new fun fact directly into the original fun fact array?
Mark Nair
3,405 PointsMark Nair
3,405 PointsHi Kyle,
I could do that, yes. I'm just trying to figure out how a user could do it with a field and a button. I'd like to understand changing the array this way so I can get a good grasp of appending an array this way. I understand pulling the info from the array, but I'm having a hard time adding to it through the data model that uses a struct and an array and an instance of the struct. Thank you!