How to set addObserver in SwiftUI?

前端 未结 6 2260
眼角桃花
眼角桃花 2021-02-13 16:35

How do I add NotificationCenter.default.addObserve in SwiftUI?

When I tried adding observer I get below error

Argument of \'#sele

6条回答
  •  耶瑟儿~
    2021-02-13 17:33

    It is not SwiftUI-native approach, which is declarative & reactive. Instead you should use NSNotificationCenter.publisher(for:object:) from Combine.

    See more details in Apple Documentation

提交回复
热议问题