NSNotificationCenter addObserver in Swift
问题 How do you add an observer in Swift to the default notification center? I\'m trying to port this line of code that sends a notification when the battery level changes. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryLevelChanged:) name:UIDeviceBatteryLevelDidChangeNotification object:nil]; 回答1: It's the same as the Objective-C API, but uses Swift's syntax. NSNotificationCenter.defaultCenter().addObserver( self, selector: #selector(batteryLevelChanged:), name: