我使用addObserver API接收通知:
NSNotificationCenter.defaultCenter().addObserver(self,selector: "methodOFReceivedNotication:",name:"NotificationIdentifier",object: nil)
我的方法是:
func methodOFReceivedNotication(notification: NSNotification){ //Action take on Notification }
是的,它的作品!
但是当我将方法methodOFReceivedNotication更改为private时:
private func methodOFReceivedNotication(notification: NSNotification){ //Action take on Notification }
xCode向我发送错误:无法识别的选择器发送到实例
当目标是自我时,如何调用私有方法?我不想将methodOFReceivedNotication方法暴露给任何其他方法.
解决方法
只需使用动态修饰符标记它,或在方法声明中使用@objc属性
dynamic private func methodOFReceivedNotication(notification: NSNotification){ //Action take on Notification }
要么
@objc private func methodOFReceivedNotication(notification: NSNotification){ //Action take on Notification }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。