I have the following code:
func compareDate() {
let query = PFQuery(className: "DailyBDate")
let calendar2 = NSCalendar.currentCalendar()
let date2 = NSDate()
let components2 = calendar2.components([.Day], fromDate: date2)
let day2 = components2.day as Int
query.whereKey("User", equalTo: self.username)
let DailyBonusDate = query.selectKeys(["Date"])
query.findObjectsInBackground()
// seems like its always something else... :/
if(day2 != DailyBonusDate) {
self.Dailybonus = 0;
self.Likelimit = 0;
self.DailybonusDefault.setValue(self.Dailybonus, forKey: "Dailybonus")
self.DailybonusDefault.synchronize()
self.LikelimitDefault.setValue(self.Likelimit, forKey: "DailyBonus")
self.LikelimitDefault.synchronize()
}
}
I have a Parse class called DailyBDate. In that class I have one column for the username and one column for the date where only the days are saved.
I want to compare the date which is saved in Parse with the current date (day2 variable). If these aren't the same (which would mean that the user logged-in in another day) swift will set the variable Dailybonus and Likelimit to 0. But if the date is the same it should stay. I tried the app but at every launch it sets the 2 variables dailybonus and Likelimit to 0 even thoogh the Date is the same. I think the problem is that you cannot compare the value saved in parse directly with a local variable.
/ Edit: Added a photo of the parse database. Parse Database