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!
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
nicole Sinclair600 Points
Log date and time when a button is pushed & at the end of the day send the log via email
I am trying to build an app that will do a number of things;
First there will be a number of buttons on the screen, I want the app to count each time it is pushed (I've gotten this)
I also want the button to open a new page with more buttons so the user can select another button, and have that counted as well, then automatically go back to the first page - i've got part too but i've been using segues and once it goes back to the first page, the data is reset. I'm not sure how to fix that. - does anyone have ideas of why its resetting, or what method I should be using to go back and forth between the screens?
Lastly I would like this app to log the date and time that the buttons are pushed, and have them at the end of the day say 23:59, the button counts will reset, and the log will be emailed to an address. - this part i've having a lot of trouble with, are there any tutorials or methods anyone can suggest I research and try?
Tuan Do3,495 Points
Tuan Do3,495 Points
I just started with swift so I might be wrong here. There are several ways to pass your counter back and forth. One is global variable although this is probably not recommended. Since classes are reference types, you can create an object with a counter stored property and pass it in a segue to the destination view controller. Any update to the object in your second page would still be there when you go back to the first page. Third is similar to the second one by using a struct with static stored property. All instances of the struct share the same static stored property. So if you create an instance in your main view controller and another in your second view controller, they both share the same static counter.