2016-06-19 3 views
0

예약 알림을 찾는 빠르고 효율적인 방법이 있습니까?예약 알림을 찾는 빠른 방법

 // To avoid duplicate notifications, check whether there are already scehduled notifications with the same fireDate, reminderName and calendar name. 
     if let definiteDueDateComponents = reminder.dueDateComponents, definiteDueDate = definiteDueDateComponents.date, definiteScheduledNotifications = UIApplication.sharedApplication().scheduledLocalNotifications { 

      for notification in definiteScheduledNotifications { 
       if notification.fireDate?.compare(definiteDueDate) == .OrderedSame { 
        // Check whether there is already a notification set up for definiteDueDate? 
        // If so, check whether the notification is actually for the same item that I want to set up here. 

       } 
      }     
     } 

이것은, 그러나, 나는 그들을 예약하기 전에 내가 (위의 코드를 실행)에 대해 검사 할 많은 항목이 특히 비효율적이 될 수 있습니다 Find list of Local Notification the app has already set 내가 무슨 짓을하는 목록을가는 설명합니다 이미 여러 가지 예약 알림이있는 경우에도 마찬가지입니다.

누구나 예약 알림 사전 (해시 테이블)을 만들었습니까? 그렇다면 언제 그것을 만들고 다시 만드십니까? 해시 테이블을 UIApplication.sharedApplication().scheduledLocalNotifications과 동기화 상태로 유지하는 것이 번거롭지 않습니까?

답변

-1

예약 된 알림이 10000 개인 경우에도 눈으로 반복적으로 걸리는 시간을 감지하지 못할 것입니다. 이전과 이후의 시간을 기록하고 차이를 계산해야하며 1/1000 초 미만일 수 있습니다.

"조기 최적화"의 경우입니다. for 루프를 사용하고 완료하십시오.

예약 된 알림이 10000 개 이상인 경우 디자인을 다시 생각해 봐야합니다.

+0

예정된 알림 수만이 아닙니다. 위에서 만든 요점은 일정 알림을받는 동안 n 번 확인을 수행해야 할 수도 있으므로 실행 시간은 O (n * m) 일 것입니다. 또한, 왜 그렇게 빨리 생각하니? 다른 유형의 I/O를 수행합니다 : 코드에서 EKEventStore로부터 1000 개의 EKReminders를 가져오고 약 10 초가 걸립니다! 확실히 눈에.니다. – Daniel

+0

이것은 다릅니다. 예약 된 알림 목록은 메모리 내 배열입니다. 그것을 반복하는 것은 매우 빠를 것이다. 그러나 O (n * m)을 피할 수있는 방법을 찾아야합니다. –

관련 문제