0

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

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);
1

1 件の回答 1

1

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

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

3
  • ご回答ありがとうございます。 代入したいのはsender.dateです。 下記、右辺にはどのように記載すればよろしいのでしょうか。 notification.fireDate =  ご回答いただければありがたいです。
    – mmmm
    2015年10月16日 14:12
  • sender.dateNSDateのインスタンスならnotification.fireDate = sender.dateでいいと思います。 2015年10月16日 14:34
  • ありがとうございます!助かりました。
    – mmmm
    2015年10月17日 5:00

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。