<分区>
我有一个这样的方法:
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)")
}
}
我从 App Delegate 调用它 -
Utility.getScheduledForToday()
print("count: \(Utility.todaysReminders.count)")
方法中的 print 打印正确的值。 App Delegate 里面的打印是空白的。我在概念上遗漏了一些东西。我知道回调比调用 getScheduledForToday 方法晚完成,因此空白。问题是如何等待回调,或者有更好的方法来实现吗?