Search code examples
iosxcodeswiftswift2uilocalnotification

trying to create a local notification but getting error " cannot call value of non function type uilocalnotification " in 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 

Solution

  • You need to call scheduleLocalNotification, not scheduledLocalNotifications (note schedule not scheduled):

    UIApplication.sharedApplication().scheduleLocalNotification(notification)