I have a method like this:
class Utility{
static var todaysNotifications = [String]()
static func getScheduledForToday() {
_ = UNUserNotificationCenter.current().getPendingNotificationRequests { (notificationRequests) in
for notificationRequest in notificationRequests {
//some logic here
todaysNotifications.append("some value based on logic")
}
}
print("count: \(todaysNotifications.count)")
}
}
I'm calling this from the App Delegate -
Utility.getScheduledForToday()
print("count: \(Utility.todaysReminders.count)")
The print inside the method prints proper value. The print inside the App Delegate is blank. I'm missing something conceptually. I know the callback is finishing later than the call to the getScheduledForToday method and hence the blank. The question is how to wait for the callback or are there better ways to achieve this?