

エラー内容  
`cannot assign a value of type "NSDateFormatter" to a value of type` "NSDate"  
エラー箇所  
`notification.fireDate = myDateFormatter`

[code]

    let myDateFormatter = NSDateFormatter()
    myDateFormatter.locale = NSLocale(localeIdentifier: "ja_JP")
    myDateFormatter.dateFormat = "yyyy/MM/dd hh:mm"
    
    let mySelectedDate: NSString = myDateFormatter.stringFromDate(sender.date)
    dateField.text = mySelectedDate as String
    
    
    UIApplication.sharedApplication().cancelAllLocalNotifications();
    let setting = UIUserNotificationSettings(forTypes: [.Sound, .Alert], categories: nil)
    UIApplication.sharedApplication().registerUserNotificationSettings(setting)
    let notification = UILocalNotification()
    notification.fireDate = myDateFormatter
    notification.timeZone = NSTimeZone.defaultTimeZone()
    notification.alertBody = "通知だよ"
    notification.alertAction = "OK"
    notification.soundName = UILocalNotificationDefaultSoundName
    UIApplication.sharedApplication().scheduleLocalNotification(notification);
    
[/code]


CC BY-SA 3.0
2015-10-16T09:05:57.870
17720
2016-02-13T21:32:01.110
2015-10-16T09:59:12.247
5519
12807
question
ios swift iphone
Swift LocalNotificationで通知時間を指定したい


エラーメッセージの通りで、`myDateFormatter`は`NSDateFormatter`のインスタンスなので、`NSDate`ではないからですね。

`fireDate`に代入したいのは`sender.date`なのではありませんか？


CC BY-SA 3.0
2015-10-16T10:01:01.630
17722
2015-10-16T10:01:01.630
5519
17720
answer