<commit_before>//
//  BPCompatibleAlertController.swift
//  RelSci
//
//  Created by <NAME> on 12/1/14.
//  Copyright (c) 2014 Relationship Science LLC. All rights reserved.
//

import Foundation
import UIKit

public typealias BPCompatibleTextFieldConfigruationHandler = ((UITextField!) -> Void)!

public enum BPCompatibleAlertControllerStyle {
    case Actionsheet
    case Alert
}

private class BPAlertView : UIAlertView {
    // Keep a strong reference to the delegate to ensure the BPCompatibleAlertController doesn't get destroyed by ARC on iOS 7
    // Once the alert button has been clicked and BPCompatibleAlertController is finished with this alert view, BPCompatibleAlertController
    //  can clear the delegateReference and ARC can clean up
    var delegateReference: BPCompatibleAlertController?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    init(title: String?, message: String?, delegate: BPCompatibleAlertController, cancelButtonTitle: String?) {
        delegateReference = delegate
        super.init(title: title, message: message, delegate: delegate, cancelButtonTitle: cancelButtonTitle)
    }
}

@objc(BPCompatibleAlertController)
public class BPCompatibleAlertController : NSObject, UIAlertViewDelegate {
    let title: String?
    let message: String?
    let alertStyle: BPCompatibleAlertControllerStyle
    
    /**
    Allows for UITextFields in iOS7 UIAlertViews. Must have corresponding counts of
    BPCompatibleTextFieldConfigurationHandlers for each style.
    Default = 0
    PlainTextInput or SecureTextInput = 1
    LoginAndPasswordInpnut = 2
    */
    public var alertViewStyle: UIAlertViewStyle
    
    /**
    If this set, when the user dismisses the alert all the resources used
    by this alert controller will be automatically released allowing this object to be deallocated.
    
    After the user has dismissed the alert, presentFrom: cannot be called again on this object.
    
    Should client code set this to false (because they intend to re-user the alert), it must at some stage call releaseResources() to
    ensure internal resources are freed up.
    
    releaseResourcesWhenAlertDismissed defaults to true.
    */
    public var releaseResourcesWhenAlertDismissed: Bool = true
    
    private var alertController: UIAlertController!
    private var alertView: BPAlertView!
    private var actions: [String : BPCompatibleAlertAction]
    private var actionObservers: Array<NSObjectProtocol> = []
    public var resourcesHaveBeenReleased: Bool = false
    private var textFieldConfigurations: [BPCompatibleTextFieldConfigruationHandler]
    private var alertControllerStyle: UIAlertControllerStyle {
        get {
            return alertStyle == BPCompatibleAlertControllerStyle.Actionsheet
                ? UIAlertControllerStyle.ActionSheet
                : UIAlertControllerStyle.Alert
        }
    }
    
    private var uiAlertControllerAvailable: Bool {
        get {
            return objc_getClass("UIAlertController") != nil
        }
    }
    
    /**
    Creates an instance of BPCompatibleAlertController.
    
    :param: title The title of the alert shown.
    :param: message The message shown for the alert below the title.
    :param: alertStyle The style to be used when displaying the alert. Currently only supporting iOS 8.
    
    :returns: The created alert controller.
    */
    public init(title: String?, message: String?, alertStyle: BPCompatibleAlertControllerStyle) {
        self.title = title
        self.message = message
        self.alertStyle = alertStyle
        self.alertViewStyle = UIAlertViewStyle.Default
        self.actions = [String : BPCompatibleAlertAction]()<commit_msg>Change array declaration to use shorthand for consistency with code base.<commit_after>//
//  BPCompatibleAlertController.swift
//  RelSci
//
//  Created by <NAME> on 12/1/14.
//  Copyright (c) 2014 Relationship Science LLC. All rights reserved.
//

import Foundation
import UIKit

public typealias BPCompatibleTextFieldConfigruationHandler = ((UITextField!) -> Void)!

public enum BPCompatibleAlertControllerStyle {
    case Actionsheet
    case Alert
}

private class BPAlertView : UIAlertView {
    // Keep a strong reference to the delegate to ensure the BPCompatibleAlertController doesn't get destroyed by ARC on iOS 7
    // Once the alert button has been clicked and BPCompatibleAlertController is finished with this alert view, BPCompatibleAlertController
    //  can clear the delegateReference and ARC can clean up
    var delegateReference: BPCompatibleAlertController?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    init(title: String?, message: String?, delegate: BPCompatibleAlertController, cancelButtonTitle: String?) {
        delegateReference = delegate
        super.init(title: title, message: message, delegate: delegate, cancelButtonTitle: cancelButtonTitle)
    }
}

@objc(BPCompatibleAlertController)
public class BPCompatibleAlertController : NSObject, UIAlertViewDelegate {
    let title: String?
    let message: String?
    let alertStyle: BPCompatibleAlertControllerStyle
    
    /**
    Allows for UITextFields in iOS7 UIAlertViews. Must have corresponding counts of
    BPCompatibleTextFieldConfigurationHandlers for each style.
    Default = 0
    PlainTextInput or SecureTextInput = 1
    LoginAndPasswordInpnut = 2
    */
    public var alertViewStyle: UIAlertViewStyle
    
    /**
    If this set, when the user dismisses the alert all the resources used
    by this alert controller will be automatically released allowing this object to be deallocated.
    
    After the user has dismissed the alert, presentFrom: cannot be called again on this object.
    
    Should client code set this to false (because they intend to re-user the alert), it must at some stage call releaseResources() to
    ensure internal resources are freed up.
    
    releaseResourcesWhenAlertDismissed defaults to true.
    */
    public var releaseResourcesWhenAlertDismissed: Bool = true
    
    private var alertController: UIAlertController!
    private var alertView: BPAlertView!
    private var actions: [String : BPCompatibleAlertAction]
    private var actionObservers: [NSObjectProtocol] = []
    public var resourcesHaveBeenReleased: Bool = false
    private var textFieldConfigurations: [BPCompatibleTextFieldConfigruationHandler]
    private var alertControllerStyle: UIAlertControllerStyle {
        get {
            return alertStyle == BPCompatibleAlertControllerStyle.Actionsheet
                ? UIAlertControllerStyle.ActionSheet
                : UIAlertControllerStyle.Alert
        }
    }
    
    private var uiAlertControllerAvailable: Bool {
        get {
            return objc_getClass("UIAlertController") != nil
        }
    }
    
    /**
    Creates an instance of BPCompatibleAlertController.
    
    :param: title The title of the alert shown.
    :param: message The message shown for the alert below the title.
    :param: alertStyle The style to be used when displaying the alert. Currently only supporting iOS 8.
    
    :returns: The created alert controller.
    */
    public init(title: String?, message: String?, alertStyle: BPCompatibleAlertControllerStyle) {
        self.title = title
        self.message = message
        self.alertStyle = alertStyle
        self.alertViewStyle = UIAlertViewStyle.Default
        self.actions = [String : BPCompatibleAlertAction]()
{'fraction_non_alphanumeric': 0.05818039828192113, 'fraction_numerical': 0.003904724716907458, 'mean_word_length': 3.3023516237402015, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, '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': '4738751', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1907, 'n_words': 693}