quick update of the weekly text label

I am a beginner of for swift.

In the homeviewController, I declare a label

    @IBOutlet weak var text: UILabel!

How can I update this number by 1 from 0 each week from the day the app is installed?


First, store the launch date somewhere the first time the app launches, for example NSUserDefaults: NSUserDefaults.standardUserDefaults().setObject(NSDate(), forKey: "installDate"). Then, whenever you need to show the label just find the difference in weeks between the current time and the stored one:

let installDate = NSUserDefaults.standardUserDefaults().objectForKey("installDate") as NSDate!
let today = NSDate()
let calendar = NSCalendar.currentCalendar()
let unitFlags = NSCalendarUnit.WeekOfYear
let dateComponents = calendar.components(unitFlags, fromDate:installDate,  toDate:today, options: NSCalendarOptions.MatchNextTime)
let weeks = dateComponents.weekOfYear