2016-05-23 31 views
-1

比方說,這個字符串數組具有其已計劃在localNotification日期的字符串,有沒有辦法讓這些字符串,並將其轉換爲日期,然後刪除某一預定日期如何取消轉換爲NSDate後從字符串數組中取得的localNotification?

var arr = ["2016-08-27 19:29:50 +0000","2016-09-20 17:19:50 +0000","2016-07-27 10:20:30 +0000"]** 

func locaNotification(num:Int) 

{ 

    let notification = UILocalNotification() 
    let notifTime = NSDate(notificationTime[num]) 
    UIApplication.sharedApplication().cancelLocalNotification(notification) 

} 
+0

查找'NSDateFormatter '把'NSDate'轉換成'NSString'或'NSString'成'NSDate'。 – Larme

回答

1
let arrLocalNotif = UIApplication.sharedApplication().scheduledLocalNotifications 
for (let localN in arrLocalNotif) { 
    let notificationFireDate = localN.fireDate; 
    //convert string array value to date object and Compair this bothdate 
    if(compair true) { 
     UIApplication.sharedApplication().cancelLocalNotification(notification) 
      break 
    } 
} 
+0

你可以用Swift寫嗎? –

+0

只是寫在Swift和它的工作=)非常感謝 –

+0

雖然我有最後一個問題! 當我在if語句兩個日期比較我得到的輸出: 2016年5月23日13時55分○○秒+0000 2016年5月23日13時53分38秒+0000 這意味着條件永遠不會是真的,因爲在幾秒鐘內總會有差異!你知道任何方法忽略比較秒? –