迅速代表? [英] Delegates in swift?
本文介绍了迅速代表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 swift 中创建一个委托,即 NSUserNotificationCenterDelegate
?
How does one go about making a delegate, i.e. NSUserNotificationCenterDelegate
in swift?
推荐答案
它与 obj-c 并没有什么不同.首先,您必须在类声明中指定协议,如下所示:
It is not that different from obj-c. First, you have to specify the protocol in your class declaration, like following:
class MyClass: NSUserNotificationCenterDelegate
实现将如下所示:
// NSUserNotificationCenterDelegate implementation
func userNotificationCenter(center: NSUserNotificationCenter, didDeliverNotification notification: NSUserNotification) {
//implementation
}
func userNotificationCenter(center: NSUserNotificationCenter, didActivateNotification notification: NSUserNotification) {
//implementation
}
func userNotificationCenter(center: NSUserNotificationCenter, shouldPresentNotification notification: NSUserNotification) -> Bool {
//implementation
return true
}
当然,你必须设置委托.例如:
Of course, you have to set the delegate. For example:
NSUserNotificationCenter.defaultUserNotificationCenter().delegate = self;
这篇关于迅速代表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文