试图创build一个本地通知,但得到错误“不能调用非函数typesuilocalnotification值”在swift 2

import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() var dateComp:NSDateComponents = NSDateComponents() dateComp.year = 2015; dateComp.month = 11; dateComp.day = 20; dateComp.hour = 0; dateComp.minute = 10; dateComp.timeZone = NSTimeZone.systemTimeZone() var calendar:NSCalendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)! var date:NSDate = calendar.dateFromComponents(dateComp)! //var date:NSDate = calendar.dateFromComponents(dateComp) var notification:UILocalNotification = UILocalNotification() notification.category = "FIRST_CATEGORY" notification.alertBody = "HI, noti " notification.fireDate = date UIApplication.sharedApplication().scheduledLocalNotifications(notification) // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } //trying to create a local notification but getting error " cannot call value of non function type uilocalnotification " in swift 2 

您需要调用scheduleLocalNotification ,而不是scheduledLocalNotifications (注意不安排schedule d ):

 UIApplication.sharedApplication().scheduleLocalNotification(notification)