在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")
答案 0 :(得分:2)
在swift中,选择键只是字符串,所以它是
NSDistributedNotificationCenter.defaultCenter().addObserver(self, selector: "allDistributedNotifications:", name: "com.apple.iTunes.playerInfo", object: "com.apple.iTunes.player")