0

I'm working on a project where I have labels and images that change on a daily basis. My idea on how to go about this is I add assets for the images and have multiple files where I take the text (that contains the quote).

Two questions:

  1. Is there a better way of approaching this? (I'm fairly new to iOS, so I'm wondering if this is sound).

  2. How can I take the current day as in: May 22? (I just want to know how to get "22").

rmaddy
  • 298,130
  • 40
  • 468
  • 517
Nick3150
  • 21
  • 6
  • Hi and welcome to StackOverflow. Please help other people to help you by following these guidelines when asking questions: http://stackoverflow.com/help/how-to-ask – Robotic Cat May 23 '16 at 02:21

2 Answers2

2

you need to use NSDate

// Option 1
let date = NSDate() // today
let dateStringFormatter = NSDateFormatter()
dateStringFormatter.dateFormat = "dd"
let d = dateStringFormatter.stringFromDate(date)
// d = "22"

// Option 2
let d = NSCalendar.currentCalendar().component(.Day, fromDate: NSDate()) // thanks Leo-Dabus

Reference: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/

sonique
  • 3,402
  • 2
  • 20
  • 33
2

Try taking a look at this stackoverflow link on getting the current date.

How to get the current time as datetime

According to noliv in the article you should be able do :

let date = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute, fromDate: date)
let hour = components.hour
let minutes = components.minute

Hope this helps

Community
  • 1
  • 1
Nate
  • 168
  • 11