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
Alain Ghiai
4,287 PointsHelp with swift
Hi, I've created a simple app of facts with swift. However I want the user to be able to read only 3 random facts a day. Can someone help me with this. Thanks, Cyrus
2 Answers
Ian Rushton
15,789 PointsI've just had a look online to see what I can find.
Looks like there is something called NSDate() which can pinpoint a set date and time that something is carried out.
There seems to be a fair bit that can be done with this so try checking...
[NSDate Link] http://www.brianjcoleman.com/tutorial-nsdate-in-swift/
... under the heading 'compare NSDate'. (Can't work out what I'm doing wrong but the link seems to have random things at the end... Delete everything after the "swift/")
Looks like this may have what you need. Hope it does!!
Alain Ghiai
4,287 PointsThanks Ian !
Alain Ghiai
4,287 PointsThanks for the help Ian,however,I'm stuck with reseting the array to 0 after 24 hours. If you found out how to do it please tell me !
Ian Rushton
15,789 PointsIan Rushton
15,789 PointsGood question.
I'm guessing you would have create a variable like factCount which would be incremented every time a fact is called and set an if statement within the function to stop carrying it out once it reaches a certain number.
Unfortunately I have no idea how you would have this reset to '0' after 24 hours... I'm a noob!
I'm interested to hear an answer to this!