Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
[ad_1]
If I wanted to hear for a notification, I’ve all the time finished like so:
NotificationCenter.default.addObserver(self, selector: #selector(foo), identify: UIApplication.didEnterBackgroundNotification, object: nil)
But when I transfer that line inside the physique of an async methodology, the compiler all of the sudden needs that line to be marked with await:
func setup() async {
let importantStuff = await someTask()
// retailer my vital stuff, now setup is full
// This line will not compile with out the await key phrase.
// However addObserver is just not even an async methodology 🤨
await NotificationCenter.default.addObserver(self, selector: #selector(foo), identify: UIApplication.didEnterBackgroundNotification, object: nil)
// However this works fantastic
hear()
}
func hear() {
NotificationCenter.default.addObserver(self, selector: #selector(foo), identify: UIApplication.didEnterBackgroundNotification, object: nil)
}
What is going on on right here?
[ad_2]