Swift等效@selector(allDistributedNotifications :)

时间:2014-07-22 12:30:31

标签: notifications swift nsnotificationcenter

在Swift中,字符串

中的@selector(allDistributedNotifications:)相当于什么

[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(allDistributedNotifications:) name:@"com.apple.iTunes.playerInfo" object:@"com.apple.iTunes.player"];

我尝试了以下操作,但收到错误消息

NSDistributedNotificationCenter.defaultCenter().addObserver(self, selector: Selector(allDistributedNotifications), name: "com.apple.iTunes.playerInfo", object: "com.apple.iTunes.player")

1 个答案:

答案 0 :(得分:2)

在swift中,选择键只是字符串,所以它是

NSDistributedNotificationCenter.defaultCenter().addObserver(self, selector: "allDistributedNotifications:", name: "com.apple.iTunes.playerInfo", object: "com.apple.iTunes.player")