我正在尝试在设备上本地存储“是”或“否”的值,日复一日。我不知道如何实现这一点,甚至不知道从哪里开始,所以我没有特别尝试任何东西。下面是我用来提示用户输入的代码。
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
// if user didnt yet provided value and time is after 6 pm then only alert will occur
let dateNow = NSDate()
let calendar = NSCalendar.currentCalendar()
let hour = calendar.component(NSCalendarUnit.Hour, fromDate: dateNow)
if Score == 0 && hour >= 18 && hour <= 21{
if !isAlertShown {
isAlertShown = true
let Alert1 = UIAlertController(title: "Meal check", message: "Had Your lunch Today", preferredStyle: .Alert)
let YesAction = UIAlertAction(title: "Yes", style: UIAlertActionStyle.Default) {
UIAlertAction in self.increaseScore()
self.ScoreView.text = "\(self.Score)"
}
let NoAction = UIAlertAction(title: "NO", style: UIAlertActionStyle.Cancel) {
UIAlertAction in self.discreaseScore()
self.ScoreView.text = "\(self.Score)"
}
Alert1.addAction(YesAction)
Alert1.addAction(NoAction)
self.presentViewController(Alert1, animated: true, completion: nil)
}
// setting if user provided value than cancel the notification and alert for today
if Score == 1 {
}
}
答案 0 :(得分:0)
我找到了一些你可能想看的教程。每个教程都采用不同的方法来本地和远程存储数据。
.pinInBackground()
即可。 Here是一个很好的教程,可以让你设置解析,here是一个很好的指南,可以使用本地数据存储。 Parse和Local Datastore。如果你问我,我个人会选择B,Parse。但你也可以使用1和3来创建完全相同的替代品,可能更安全,因为它完全取决于Apple自己的技术。
希望有帮助,朱利安。