How to set addObserver in SwiftUI?

前端 未结 6 2157
眼角桃花
眼角桃花 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:10

    This worked for me

       let NC = NotificationCenter.default
    
    
    
       self.NC.addObserver(forName: .NEVPNStatusDidChange, object: nil, queue: nil, 
                           using: self.VPNDidChangeStatus)
    
    
       func VPNDidChangeStatus(_ notification: Notification) {
    
    
        }
    

提交回复
热议问题