<commit_before>//
//  AlertController.swift
//  APExtensions
//
//  Created by <NAME> on 4/26/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit

// ******************************* MARK: - Helper Class

fileprivate final class AlertRootViewController: UIViewController {
    fileprivate var customPreferredStatusBarStyle = UIStatusBarStyle.lightContent
    fileprivate var customPrefersStatusBarHidden = false
    
    override var prefersStatusBarHidden: Bool {
        return customPrefersStatusBarHidden
    }
    
    override var preferredStatusBarStyle : UIStatusBarStyle {
        return customPreferredStatusBarStyle
    }
}

// ******************************* MARK: - Class Implementation

public final class AlertController: UIAlertController {
    
    // ******************************* MARK: - Types
    
    public enum PresentationStyle {
        /// Present in separate window
        case window
        
        /// Present in key window from top presented controller
        case topController
    }
    
    // ******************************* MARK: - Classes Properties
    
    public static var presentationStyle: PresentationStyle = .window
    
    // ******************************* MARK: - Private Properties
    
    private lazy var rootVC: AlertRootViewController = {
        let rootVC = AlertRootViewController()
        let topVc = g_statusBarStyleTopViewController
        
        rootVC.customPrefersStatusBarHidden = topVc?.prefersStatusBarHidden ?? false
        
        if (Bundle.main.object(forInfoDictionaryKey: "UIViewControllerBasedStatusBarAppearance") as! Bool?) ?? true {
            rootVC.customPreferredStatusBarStyle = topVc?.preferredStatusBarStyle ?? .default
        } else {
            if let barStyle = topVc?.navigationController?.navigationBar.barStyle {
                rootVC.customPreferredStatusBarStyle = barStyle == .black ? .lightContent : .default
            }
        }
        
        return rootVC
    }()
    
    private lazy var alertWindow: UIWindow? = {
        let alertWindow = UIWindow(frame: UIScreen.main.bounds)
        alertWindow.windowLevel = UIWindowLevelAlert
        alertWindow.rootViewController = self.rootVC
        
        return alertWindow
    }()
    
    // ******************************* MARK: - UIViewController Methods
    
    override public func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        
        alertWindow?.isHidden = true
        alertWindow = nil
    }
    
    // ******************************* MARK: - Public Methods
    
    public func present(animated: Bool, completion: (() -> Void)? = nil) {
        g_performInMain {
            switch AlertController.presentationStyle {
            case .window:
                self.alertWindow?.makeKeyAndVisible()
                self.alertWindow?.rootViewController?.present(self, animated: animated, completion: completion)
                
            case .topController:
                g_topViewController?.present(self, animated: animated, completion: completion)
            }
        }
    }
}
<commit_msg>- Unneeded window allocation fix for AlertController<commit_after>//
//  AlertController.swift
//  APExtensions
//
//  Created by <NAME> on 4/26/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit

// ******************************* MARK: - Helper Class

fileprivate final class AlertRootViewController: UIViewController {
    fileprivate var customPreferredStatusBarStyle = UIStatusBarStyle.lightContent
    fileprivate var customPrefersStatusBarHidden = false
    
    override var prefersStatusBarHidden: Bool {
        return customPrefersStatusBarHidden
    }
    
    override var preferredStatusBarStyle : UIStatusBarStyle {
        return customPreferredStatusBarStyle
    }
}

// ******************************* MARK: - Class Implementation

public final class AlertController: UIAlertController {
    
    // ******************************* MARK: - Types
    
    public enum PresentationStyle {
        /// Present in separate window
        case window
        
        /// Present in key window from top presented controller
        case topController
    }
    
    // ******************************* MARK: - Classes Properties
    
    public static var presentationStyle: PresentationStyle = .window
    
    // ******************************* MARK: - Private Properties
    
    private lazy var rootVC: AlertRootViewController = {
        let rootVC = AlertRootViewController()
        let topVc = g_statusBarStyleTopViewController
        
        rootVC.customPrefersStatusBarHidden = topVc?.prefersStatusBarHidden ?? false
        
        if (Bundle.main.object(forInfoDictionaryKey: "UIViewControllerBasedStatusBarAppearance") as! Bool?) ?? true {
            rootVC.customPreferredStatusBarStyle = topVc?.preferredStatusBarStyle ?? .default
        } else {
            if let barStyle = topVc?.navigationController?.navigationBar.barStyle {
                rootVC.customPreferredStatusBarStyle = barStyle == .black ? .lightContent : .default
            }
        }
        
        return rootVC
    }()
    
    private lazy var alertWindow: UIWindow? = {
        let alertWindow = UIWindow(frame: UIScreen.main.bounds)
        alertWindow.windowLevel = UIWindowLevelAlert
        alertWindow.rootViewController = self.rootVC
        
        return alertWindow
    }()
    
    // ******************************* MARK: - UIViewController Methods
    
    override public func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        
        if AlertController.presentationStyle == .window {
            alertWindow?.isHidden = true
            alertWindow = nil
        }
    }
    
    // ******************************* MARK: - Public Methods
    
    public func present(animated: Bool, completion: (() -> Void)? = nil) {
        g_performInMain {
            switch AlertController.presentationStyle {
            case .window:
                self.alertWindow?.makeKeyAndVisible()
                self.alertWindow?.rootViewController?.present(self, animated: animated, completion: completion)
                
            case .topController:
                g_topViewController?.present(self, animated: animated, completion: completion)
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.13695413992800126, 'fraction_numerical': 0.0028173423070903115, 'mean_word_length': 2.480392156862745, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5034590', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1524, 'n_words': 365}