Good day. I want my application to show the time of sunrise and sunset on every day. Please tell me how to change the UITextField value on a given date.

  • 2
    Please give an example of your code, explain what causes you difficulty. Or do you just want a ready-made solution ?. How to ask a question: www.stackoverflow.com/help/mcve - spectre_it
  • @ stas0k I want the direction shown at least. My code does not work and he can do the same thing every day - Muhammadnakshubandi Lobsters
  • 2
    However, it is worthwhile to bring in your code, even if it is non-working. This way you will receive a more accurate recommendation, you may see something that will save you from new questions and give you the opportunity to understand where you are going without relying on best practice. There is nothing shameful about the non-working code. - AK
  • What exactly you can not do? - Max Mikheyenko
  • @MaxMikheyenko So that the application displays the text on the screen on a given day ... At least for a start ... And then there are different texts for each day ... - Muhammadnakshubandi Omarov

1 answer 1

on the Internet offer two dates to compare so

- (BOOL)isSameDay:(NSDate*)date1 otherDay:(NSDate*)date2 { NSCalendar* calendar = [NSCalendar currentCalendar]; unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; NSDateComponents* comp1 = [calendar components:unitFlags fromDate:date1]; NSDateComponents* comp2 = [calendar components:unitFlags fromDate:date2]; return [comp1 day] == [comp2 day] && [comp1 month] == [comp2 month] && [comp1 year] == [comp2 year]; } 
  • Now I am facing another problem. If the application is not closed but is in the background, the text for the next day is not updated ... If you close it completely and open it then it shows everything correctly ... how can you decide? THANK! - Muhammadnakshubandi