提问者:小点点

Swift等效@Selector(AllDistributedNotifications:)[重复]


在Swift中,字符串中的@selector(alldistributednotifications:)的等价物是什么

[NSDistributedNotificationCenter defaultCenter]AddObserver:Self Selector:@Selector(AllDistributedNotifications:)Name:@“com.apple.itunes.playerInfo”对象:@“com.apple.itunes.player”];

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

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

共1个答案

匿名用户

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

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