-1

In Swift, what is the equivalent of @selector(allDistributedNotifications:) in string

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

I tried the following, but I get an error message

NSDistributedNotificationCenter.defaultCenter().addObserver(self, selector: Selector(allDistributedNotifications), name: "com.apple.iTunes.playerInfo", object: "com.apple.iTunes.player")
JuJoDi
  • 14,627
  • 23
  • 80
  • 126
gJamDev
  • 81
  • 1
  • 11

1 Answers1

2

In swift the selector keys are just strings so it would be

NSDistributedNotificationCenter.defaultCenter().addObserver(self, selector: "allDistributedNotifications:", name: "com.apple.iTunes.playerInfo", object: "com.apple.iTunes.player")
JuJoDi
  • 14,627
  • 23
  • 80
  • 126
  • @gJamDev Also note I added back in the colon as well, which you didn't have in your swift attempt - which will send self as the first parameter to the `allDistributedNotifications` function – JuJoDi Jul 22 '14 at 12:36
  • I rewrite this code and can't understand (in this part) how convert it into swift (full code) `- (void)getter{ [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(allDistributedNotifications:) name:@"com.apple.iTunes.playerInfo" object:@"com.apple.iTunes.player"]; } - (void) allDistributedNotifications:(NSNotification *)note {/*..*/}` – gJamDev Jul 22 '14 at 12:43
  • @gJamDev please ask a different question.. but search for duplicates first :D – JuJoDi Jul 22 '14 at 13:50
  • selectors are not "just strings" -- they are `Selector`s -- it's just that `Selector` is `StringLiteralConvertible`, so you can use a string literal to specify it – newacct Jul 22 '14 at 18:04