NSNotificationCenter addObserver in Swift while call a private method

前端 未结 2 1338
离开以前
离开以前 2021-02-19 19:15

I use the addObserver API to receive notification:

NSNotificationCenter.defaultCenter().addObserver(self, selector: \"methodOFReceivedNotication:\",         


        
2条回答
  •  失恋的感觉
    2021-02-19 20:09

    Just mark it with the dynamic modifier or use the @objc attribute in your method declaration

    dynamic private func methodOFReceivedNotication(notification: NSNotification){
        //Action take on Notification
    }
    

    or

    @objc private func methodOFReceivedNotication(notification: NSNotification){
        //Action take on Notification
    }
    

提交回复
热议问题