Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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?