Quote:
Originally Posted by hiddesteenbeek
i have a question: i want to create an app that has a different text at the screen everyday by date. so for example:
on 5 july 2011: hi this is day 1
on 6 july 2011: hi this looks boring.
can someone please help me, thank you.
sorry for my english, i am dutch
|
You need to provide more information. Where would these strings come from? Would they be stored in a file somewhere? Do you want to pick them randomly, or do you want to display them in order from the beginning to the end of a list of messages?
How do you decide which is day 1? If you assign 5 July 2011 as day 1, and have 200 strings, what happens when you release your app to the store, 201 days later? At that point your app is out of strings.
Without knowing more about what you want to do, I can only point you at the system components that you need.
The NSCalendar class lets you calculate the difference between 2 dates in any units you want. If 5 July is your day 1, you could create an NSDate that represents 5 July, and then use the NSCalendar method
components:fromDate:toDate
ptions: to calculate the number of days from your 5 July date to the current date. You could then use that day number as an index into a table of message strings, if that's what you wanted.
Take a look at the XCode documentation on that method. It includes sample code that shows how to calculate the number of months and days between 2 dates. It could be easily modified to calculate the number of days between 2 dates instead.