- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在发出通知并观看有关它的教程,当我输入时:
notification.fireDate = NSDate(timeIntervalSinceNow: 0)
它说
Argument labels '(timeIntervalSinceNow:)' do not match any available overloads
我该如何解决这个问题?这是我的代码:
import UIKit
import UserNotifications
class ViewController: UIViewController {
var timer = Timer()
var time = 10
override func viewDidLoad() {
super.viewDidLoad()
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: Selector(("Notification")), userInfo: nil, repeats: true)
// Do any additional setup after loading the view, typically from a nib.
}
func notification() {
time -= 1
if time <= 0 {
let notification = UILocalNotification()
notification.alertAction = "Call"
notification.alertBody = "You have a call right now"
notification.fireDate = NSDate(timeIntervalSinceNow: 0)
UIApplication.shared.scheduleLocalNotification(notification)
timer.invalidate()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func pushNotification(_ sender: AnyObject) {
let AlertView = UIAlertController(title: "Time for your call!", message: "Press go to continue", preferredStyle: .alert)
AlertView.addAction(UIAlertAction(title: "Go", style: .default, handler: nil))
self.present(AlertView, animated: true, completion: nil)
}
}
最佳答案
swift 3
let minute:TimeInterval = 11.0 * 60.0;
Date(timeIntervalSinceNow: minute);
到现在 +11 分钟。
关于ios - 如何在 Swift3 中执行 timeIntervalSinceNow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39605714/
我的代码看起来像这样: NSDate *currDate; if(someCondition) { currDate = [NSDate date]; } //do some work
timeInterval 不断返回随机数。我认为间隔会随着每次调用而继续增加,但有时我会得到负数,有时会得到正数。 NSDate *date = groceryItem.lastPurchased;
我想在屏幕上显示自某个事件以来耗时。我有一个成员变量 NSDate *_startTime; 我像这样分配它(并启动计时器): _startTime = [NSDate date]; _timer =
我使用 timeIntervalSinceNow 函数来确定特定时间与当前时间之间的差异。我已使用 .DropAll 的“ZeroFormattingBehaviour”来删除日期中的任何 0。不过我
您好,我正在尝试查找某个日期与当前本地时间之间的时间间隔。 var a = eventDate.timeIntervalSinceNow println(a) //1404567.32182503 -
我正在尝试使用 Cloudkit(在 SWIFT 中)查询过去 1 小时内创建的记录 我试过: let predicate = NSPredicate(predicateWithFormat : "t
我正在发出通知并观看有关它的教程,当我输入时: notification.fireDate = NSDate(timeIntervalSinceNow: 0) 它说 Argument labels '
希望有人能帮忙解决这个问题。尝试使用 -timeIntervalSinceNow 方法时,我一直收到错误访问错误。我在这个类中有一个名为 NSDate *startDate 的变量,我添加了 @pro
这个问题在这里已经有了答案: "CGFloat is not convertible to Int" when trying to calculate an expression (1 个回答) 关
我不明白文档中的这个例子:timeIntervalSinceNow 方法应该显示正值,但我们如何才能达到代码中提到的“5”? (我认为它要么多于 0 要么少于 0,或者 -10 、-20、-30 等.
我正在尝试研究 Swift 2 中的 NSDate 类。 我发现每个NSDate对象都有三个属性,分别是: timeIntervalSinceReferenceDate timeIntervalSin
以下是一些来自 iOS 的示例代码: NSDate *startDateX = [NSDate date]; // Do a bunch of stuff NSLog(@"Time differenc
我是一名优秀的程序员,十分优秀!