Detect Orientation for iOS

ViewController

self.interfaceOrientation is deprecated.
How to detect orientation?

willRotateToInterfaceOrientation (swift)

override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
   if (toInterfaceOrientation.isLandscape) {
      NSLog("Landscape");
   }
   else {
      NSLog("Portrait");
   }
}

willRotateToInterfaceOrientation (Objective-C)

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
   if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
      NSLog("Portrait");
   }
   else {
      NSLog("Landscape");
   }
}

After rotating

Use UIApplication, statusBarOrientation property.

override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
   let app = UIApplication.sharedApplication()
        
   if (app.statusBarOrientation.isLandscape) {
      NSLog("App Landscape");
   }
   else {
      NSLog("App Portrait");
   }
}