                         // Use the status bar orientation as the initial video orientation. Subsequent orientation changes are handled by
                         // -[viewWillTransitionToSize:withTransitionCoordinator:].
                         let statusBarOrientation:UIInterfaceOrientation = UIApplication.sharedApplication().statusBarOrientation;
-                        var initialVideoOrientation:AVCaptureVideoOrientation = AVCaptureVideoOrientation.Portrait;
-                        
-                        /* 
-                         mapping
-                         
-                         public enum AVCaptureVideoOrientation : Int {
-                         
-                         case Portrait
-                         case PortraitUpsideDown
-                         case LandscapeRight
-                         case LandscapeLeft
-                         }
-                         
-                         public enum UIInterfaceOrientation : Int {
-                         
-                         case Unknown
-                         case Portrait
-                         case PortraitUpsideDown
-                         case LandscapeLeft
-                         case LandscapeRight
-                         }
-                         
-                         */
-                        
-                        switch statusBarOrientation {
-                        case .Portrait:
-                            initialVideoOrientation = AVCaptureVideoOrientation.Portrait
-                            break;
-                        case .LandscapeLeft:
-                            initialVideoOrientation = AVCaptureVideoOrientation.LandscapeLeft
-                            break;
-                        case .LandscapeRight:
-                            initialVideoOrientation = AVCaptureVideoOrientation.LandscapeRight
-                            break;
-                        case .PortraitUpsideDown:
-                            initialVideoOrientation = AVCaptureVideoOrientation.PortraitUpsideDown
-                            break;
-                        default:
-                            break;
-                        }
                         
                         if let previewLayer:AVCaptureVideoPreviewLayer = preview.layer as? AVCaptureVideoPreviewLayer {
-                            previewLayer.connection.videoOrientation = initialVideoOrientation;
+                            previewLayer.connection.videoOrientation = statusBarOrientation.toAVCaptureVideoOrientation();
                         }
                     }
                 }

    // MARK: handler
    var onCompleteInitialization: ((CameraManualSetupResult) -> (Void))? = nil
    
    private func setupWithPreview(preview:UIView) {
        let authorizationStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
        
        switch (authorizationStatus) {

enum CameraManualSetupResult: Int {
    case Success, CameraNotAuthorized, SessionConfigurationFailed
}
/**
 mapping
 
 public enum AVCaptureVideoOrientation : Int {
 
 case Portrait
 case PortraitUpsideDown
 case LandscapeRight
 case LandscapeLeft
 }
 
 public enum UIInterfaceOrientation : Int {
 
 case Unknown
 case Portrait
 case PortraitUpsideDown
 case LandscapeLeft
 case LandscapeRight
 }
 */
extension UIInterfaceOrientation {
    func toAVCaptureVideoOrientation() -> (AVCaptureVideoOrientation) {
        switch self {
        case .Portrait:
            return AVCaptureVideoOrientation.Portrait
        case .LandscapeLeft:
            return AVCaptureVideoOrientation.LandscapeLeft
        case .LandscapeRight:
            return AVCaptureVideoOrientation.LandscapeRight
        case .PortraitUpsideDown:
            return AVCaptureVideoOrientation.PortraitUpsideDown
        default:
            return AVCaptureVideoOrientation.Portrait
        }
    }
}

class Camera: NSObject {
    // MARK: properties
    internal var session: AVCaptureSession = AVCaptureSession.init()
