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

Adding textfield entries to an array

I would like to be able to add what the user has entered into a textfield, into an array. I would like the array to store all of the words that the user has entered. However I would also like to assign the number of times the user has entered that word in the array. I'd like it as an action from a button. How would I do this? Thanks!

1 Answer

Mike Gabriel
Mike Gabriel
8,402 Points

I'm not sure I fully understand the order you would like to accomplish but you would setup an IBAction for the button that fires addObject: to the NSMutableArray.

As for counting duplicates in the array you could store all of your objects from the array into an NSCountedSet and then use countForObject:

https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSCountedSet_Class/Reference/Reference.html#//apple_ref/occ/instm/NSCountedSet/countForObject:

Rashii Henry
Rashii Henry
16,433 Points

Mike, have you created any ios applications before?

Rashii Henry
Rashii Henry
16,433 Points

Mike, have you created any ios applications before?

Mike Gabriel
Mike Gabriel
8,402 Points

Yes, I have two live in the App Store and one no longer under development.

Rashii Henry
Rashii Henry
16,433 Points

do you mind if i check them out? and do you mind if i ask how long have you been involved into development?