代理在swift?

前端之家收集整理的这篇文章主要介绍了代理在swift?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何做一个委托,即NSUserNotificationCenterDelegate在swift?
它与obj-c没有什么不同。
首先,必须在类声明中指定协议,如下所示:
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
}

当然,你必须设置委托。例如:

NSUserNotificationCenter.defaultUserNotificationCenter().delegate = self;
原文链接:https://www.f2er.com/swift/321631.html

猜你在找的Swift相关文章