title: How to get a day of the week variable - Swift 2, Xcode, ViewController.swift
body: <p>I am new to code. I just want someone to tell me how I can get a day of the week variable in my code and where should I put it. Do I put it in ViewController.swift, AppDelegate.swift, where?</p>
  
  <p>I then want to program a button to go to a certain View Controller using performSeguewithIdentifier. I have made the identifiers 1Mon, 1Tue, 1Wed, 1Thu and 1Fri, each going from a certain view controller to another.</p>
  
  <p>When you provide the day of the week variable code, I need to know where to put it in because it is driving me round the bend. When I get the code, how do I implement it to a button. I have attempted to do this.</p>
  
  <pre><code>@IBAction func Wk1(sender: AnyObject) {
              if var weekDay == "Monday" {
              performSegueWithIdentifier("1Mon", sender: nil)
          }
      }
  </code></pre>
  
  <p>I have no idea where to put the code to make the variable weekDay so that is one possible reason why this code is failing. I also do not know how to format the if command while including a variable. I've tried putting the code I have been given and found in AppDelegate.swift, and in ViewController.swift I tried putting it under <code>@IBAction func Wk1(sender: AnyObject) {</code> and under <code>import UIKit</code>. All 3 didn't work. I have tried using the following code.</p>
  
  <pre><code>func getDayOfWeek(today:String)-&gt;Int? {
      let formatter  = NSDateFormatter()
      formatter.dateFormat = "yyyy-MM-dd"
      if let todayDate = formatter.dateFromString(today) {
          let myCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
          let myComponents = myCalendar.components(.CalendarUnitWeekday, fromDate: todayDate)
          let weekDay = myComponents.weekday
          return weekDay
      } else {
          return nil
      }
  }
  </code></pre>