mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-06-19 07:00:39 +08:00
* Add merge status tests * Introduce containsAll and containsNone * Rename containsAll to containsOnly
39 lines
1.0 KiB
Swift
39 lines
1.0 KiB
Swift
//
|
|
// UIViewController+CancelAction.swift
|
|
// Freetime
|
|
//
|
|
// Created by Ryan Nystrom on 10/8/17.
|
|
// Copyright © 2017 Ryan Nystrom. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
extension UIViewController {
|
|
|
|
func cancelAction_onCancel(
|
|
texts: [String?],
|
|
title: String = NSLocalizedString("Unsaved Changes", comment: ""),
|
|
message: String
|
|
) {
|
|
let dismissBlock = {
|
|
self.dismiss(animated: trueUnlessReduceMotionEnabled)
|
|
}
|
|
|
|
// dismiss if all text entries are empty
|
|
let canDismissNow = texts.containsOnly { $0 == nil || $0!.isEmpty }
|
|
if canDismissNow {
|
|
dismissBlock()
|
|
} else {
|
|
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
alert.addActions([
|
|
AlertAction.goBack(),
|
|
AlertAction.discard { _ in
|
|
dismissBlock()
|
|
}
|
|
])
|
|
present(alert, animated: trueUnlessReduceMotionEnabled)
|
|
}
|
|
}
|
|
|
|
}
|