<commit_before>//
//  DBAlertController.swift
//  DBAlertController
//
//  Created by <NAME> on 5/11/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit

public class DBAlertController: UIAlertController {
   
    /// The UIWindow that will be at the top of the window hierarchy. The DBAlertController instance is presented on the rootViewController of this window.
    private lazy var alertWindow: UIWindow = {
        let window = UIWindow(frame: UIScreen.mainScreen().bounds)
        window.rootViewController = UIViewController()
        window.backgroundColor = UIColor.clearColor()
        window.windowLevel = UIWindowLevelAlert + 1 // Guarantees that our UIAlertController will appear above all other UIAlertControllers.
        return window
    }()
    
    /**
    Present the DBAlertController on top of the visible UIViewController.
    
    :param: flag       Pass true to animate the presentation; otherwise, pass false. The presentation is animated by default.
    :param: completion The closure to execute after the presentation finishes.
    */
    public func show(animated flag: Bool = true, completion: (() -> Void)? = nil) {
        /**
        *  We don't need to worry about removing the window manually. The only strong reference to the alertWindow is the UIAlertController so when ARC cleans up the UIAlertController the alertWindow is removed.
        */
        alertWindow.makeKeyAndVisible()
        
        alertWindow.rootViewController!.presentViewController(self, animated: flag, completion: completion)
    }
    
    /**
    Dismiss the DBAlertController
    
    :param: flag       Pass true to animate the presentation; otherwise, pass false. The presentation is animated by default.
    :param: completion The closure to execute after the dismiss finishes.
    */
    public func dismiss(animated flag: Bool = true, completion: (() -> Void)? = nil) {
        dismissViewControllerAnimated(flag, completion: completion)
    }
    
    
    // Fix for bug in iOS 9 Beta 5 that prevents the original window from becoming keyWindow again
    deinit {
        alertWindow.hidden = true
    }
}<commit_msg>Making the show method a little safer<commit_after>//
//  DBAlertController.swift
//  DBAlertController
//
//  Created by <NAME> on 5/11/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit

public class DBAlertController: UIAlertController {
   
    /// The UIWindow that will be at the top of the window hierarchy. The DBAlertController instance is presented on the rootViewController of this window.
    private lazy var alertWindow: UIWindow = {
        let window = UIWindow(frame: UIScreen.mainScreen().bounds)
        window.rootViewController = UIViewController()
        window.backgroundColor = UIColor.clearColor()
        window.windowLevel = UIWindowLevelAlert + 1 // Guarantees that our UIAlertController will appear above all other UIAlertControllers.
        return window
    }()
    
    /**
    Present the DBAlertController on top of the visible UIViewController.
    
    :param: flag       Pass true to animate the presentation; otherwise, pass false. The presentation is animated by default.
    :param: completion The closure to execute after the presentation finishes.
    */
    public func show(animated flag: Bool = true, completion: (() -> Void)? = nil) {
        if let rootViewController = alertWindow.rootViewController {
            alertWindow.makeKeyAndVisible()
            
            rootViewController.presentViewController(self, animated: flag, completion: completion)
        }
    }
    
    /**
    Dismiss the DBAlertController
    
    :param: flag       Pass true to animate the presentation; otherwise, pass false. The presentation is animated by default.
    :param: completion The closure to execute after the dismiss finishes.
    */
    public func dismiss(animated flag: Bool = true, completion: (() -> Void)? = nil) {
        dismissViewControllerAnimated(flag, completion: completion)
    }
    
    
    // Fix for bug in iOS 9 Beta 5 that prevents the original window from becoming keyWindow again
    deinit {
        alertWindow.hidden = true
    }
}
{'fraction_non_alphanumeric': 0.0737294201861131, 'fraction_numerical': 0.00572655690765927, 'mean_word_length': 2.877890841813136, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '7239958', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1015, 'n_words': 411}