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
Nick Rodriguez
294 PointsKeyboard Input
I am building off of the basic swift app of displaying a fun fact. I want to add a button that when pressed will allow you to input your own custom fact. Any help? Thanks
1 Answer
Kyle Pontius
6,190 PointsHey Nick,
I don't know if you've figured this out yet, but your question is a good one. Unfortunately, because it is fairly in-depth it'll be difficult to answer without writing quite a bit of explanation, likely repeating principles others have detailed very well. I'll write an overview w/ some principles to get you well on your way:
1 - Can you do this?
Yes, with the right tools it will be "relatively" easy.
2 - What do I need?
Google: "Mutable arrays for Swift" -- Click Here for an example of the difference between Mutable and Immutable Arrays. Mutable just means you can add or remove objects from the array. This array will store your original facts, then allow you to add new facts as desired. (NOTE: Please notice, however, that when the app is fully exited, the app will lose whatever additional facts you added unless written to memory on the phone. That would be very advanced, probably above and beyond what you want to do)
Google: "Using buttons in storyboard" -- I found a great tutorial using this search term that should answer most of your questions, Click Here. The only downside is that it's in Objective-C, and your app is in Swift. This will get you well on your way to getting input, but you'll have to do a little more "Googling" on how to use UIButtons and UITextFields in Swift. It's really not hard, but getting all the pieces put together may take some time.
3 - How long should this take?
Well, obviously this is based on your experience and skillset. However, knowing most of what it would take from my perspective, I could complete this update in less than an hour. For one still learning about UIButtons, UITextFields, etc it may take the better part of a day. Keep in mind, though, these are great skills to have, and an update to your app like this will teach you a great deal. Using textfields and buttons are incredibly useful, in fact I think most apps I know of have them (even if just to log in).
Be persistent, it will take some effort. Feel free to respond to this thread. That'll send me an email and I'll be happy to answer any specific questions you have.
Good luck!
-- Kyle
Nick Rodriguez
294 PointsNick Rodriguez
294 PointsWow, thanks Kyle. I really appreciate the response. I will be working on this over the weekend!