I have a nice idea of an app and I am new in swift. The app is about a week schedule, you can add some things you have to do in a schedule.For example, on Monday you have to clean the bathroom and get milk. You can add this two things to the day plan for Monday. But my really problem is that I want the app to show the schedule of the current day when you open it. I don't have any idea how to check the day of the week so the schedule when you open the app is for the current day. It will be easy if I add a label named dayname on the top and it should show the name of the current weekday !!
Asked
Active
Viewed 375 times
-1
-
1[Date and Time Programming Guide](https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/DatesAndTimes/DatesAndTimes.html). – The code samples are still in Objective-C, but you should read it to understand the concepts of dates, calendars etc. Then you can lookup the NSCalendar documentation which is for both Swift and Objective-C. – Martin R Sep 19 '15 at 11:54
-
Possible Duplicate, check this http://stackoverflow.com/questions/25533147/get-day-of-week-using-nsdate-swift – Anina Sep 19 '15 at 11:57
-
@Amina I have seen that and tried to add it to my all but it doesn't worked .. Is there an other way? – user5289721 Sep 19 '15 at 11:58
-
Add some code to you question then, so that we can help. (or not) – Anina Sep 19 '15 at 12:01
-
I have no code now because all the code is arround my problem if I cannot check the weekday then I can't do anything.. – user5289721 Sep 19 '15 at 12:05
-
Next time start coding before asking, trying and practicing help you learn. (advice) – Anina Sep 19 '15 at 12:27
1 Answers
1
I did not try it, but this post seems to be clear with enough details and examples dealing with dates in Swift. Check it HERE
here is an example from the same source working with NSDateComponents weekday property:
// First Saturday of March 2015, US/Eastern
let firstSaturdayMarch2015DateComponents = NSDateComponents()
firstSaturdayMarch2015DateComponents.year = 2015
firstSaturdayMarch2015DateComponents.month = 3
firstSaturdayMarch2015DateComponents.weekday = 7
firstSaturdayMarch2015DateComponents.weekdayOrdinal = 1
firstSaturdayMarch2015DateComponents.hour = 11
firstSaturdayMarch2015DateComponents.minute = 0
firstSaturdayMarch2015DateComponents.timeZone = NSTimeZone(name: "US/Eastern")
// On my system (US/Eastern time zone), the result for the line below is
// "Mar 7, 2015, 11:00 AM"
let firstSaturdayMarch2015Date = userCalendar.dateFromComponents(firstSaturdayMarch2015DateComponents)!
It says :
- NSDateComponents‘ weekday property lets you specify a weekday numerically. In Cocoa’s Gregorian calendar, the first day is Sunday, and is represented by the value 1. Monday is represented by 2, Tuesday is represented by 3, all the way to Saturday, which is represented by 7.

Anina
- 453
- 3
- 18