Ios 如何为通知对象设置“UIDevice.currentDevice()”?
当我添加设备方向更改通知时,如下所示:Ios 如何为通知对象设置“UIDevice.currentDevice()”?,ios,notifications,swift,uidevice,Ios,Notifications,Swift,Uidevice,当我添加设备方向更改通知时,如下所示: NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector(layoutPages), name: UIDeviceOrientationDidChangeNotification as String!, object: UIDevice.currentDevice()) 我收到一个错误“UIDevice与任何对象都不相
NSNotificationCenter.defaultCenter().addObserver(self,
selector: Selector(layoutPages),
name: UIDeviceOrientationDidChangeNotification as String!,
object: UIDevice.currentDevice())
我收到一个错误“UIDevice与任何对象都不相同”,因此如何修复它?第二个参数有问题,它应该是字符串。此外,将UIDevice向上转换到任何对象将有助于:
NSNotificationCenter.defaultCenter().addObserver(self,
selector: Selector("layoutPages"),
name: UIDeviceOrientationDidChangeNotification as NSString!,
object: UIDevice.currentDevice() as AnyObject)