<commit_before>//
//  UIAlertControllerFactory.swift
//  shared-utils
//
//  Created by <NAME> on 10/25/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

extension UIViewController {

    func confirmDestructiveAction(actionName: String, message: String, cancelLabel: String, actionBlock: @escaping (() -> ())) {
        showCancellableAlert(withTitle: "Confirm \(actionName)", message: message, confirmTitle: "Yes, \(actionName)", cancelTitle: cancelLabel, style: .actionSheet, completion: { confirmed in
            if confirmed {
                actionBlock()
            }
        })
    }

    func showAlert(withTitle title: String, message: String, confirmTitle: String = "OK", completion: (() -> ())? = nil) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: confirmTitle, style: .destructive, handler: { action in
            completion?()
        }))
        present(alert, animated: true, completion: nil)
    }

    func showCancellableAlert(withTitle title: String, message: String, confirmTitle: String = "OK", cancelTitle: String = "Cancel", style: UIAlertControllerStyle = .alert, completion: ((Bool) -> Void)? = nil) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: style)
        alert.addAction(UIAlertAction(title: confirmTitle, style: .destructive, handler: { action in
            completion?(true)
        }))
        alert.addAction(UIAlertAction(title: cancelTitle, style: .cancel, handler: { action in
            completion?(false)
        }))
        present(alert, animated: true, completion: nil)
    }
    
}<commit_msg>make alert title/message optional and default to nil<commit_after>//
//  UIAlertControllerFactory.swift
//  shared-utils
//
//  Created by <NAME> on 10/25/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

extension UIViewController {

    func confirmDestructiveAction(actionName: String, message: String, cancelLabel: String, actionBlock: @escaping (() -> ())) {
        showCancellableAlert(withTitle: "Confirm \(actionName)", message: message, confirmTitle: "Yes, \(actionName)", cancelTitle: cancelLabel, style: .actionSheet, completion: { confirmed in
            if confirmed {
                actionBlock()
            }
        })
    }

    func showAlert(withTitle title: String? = nil, message: String? = nil, confirmTitle: String = "OK", completion: (() -> ())? = nil) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: confirmTitle, style: .destructive, handler: { action in
            completion?()
        }))
        present(alert, animated: true, completion: nil)
    }

    func showCancellableAlert(withTitle title: String? = nil, message: String? = nil, confirmTitle: String = "OK", cancelTitle: String = "Cancel", style: UIAlertControllerStyle = .alert, completion: ((Bool) -> Void)? = nil) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: style)
        alert.addAction(UIAlertAction(title: confirmTitle, style: .destructive, handler: { action in
            completion?(true)
        }))
        alert.addAction(UIAlertAction(title: cancelTitle, style: .cancel, handler: { action in
            completion?(false)
        }))
        present(alert, animated: true, completion: nil)
    }
    
}
{'fraction_non_alphanumeric': 0.12590031691155287, 'fraction_numerical': 0.005762028233938346, 'mean_word_length': 3.1580838323353295, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '136590', 'n_tokens_mistral': 966, 'n_tokens_neox': 924, 'n_words': 263}