ViewController+Alerts.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // ViewController+Alerts.swift
  3. // SheeeeeeeeetExample
  4. //
  5. // Created by Daniel Saidi on 2017-11-27.
  6. // Copyright © 2017 Daniel Saidi. All rights reserved.
  7. //
  8. import UIKit
  9. import Sheeeeeeeeet
  10. extension ViewController {
  11. func alert(button: UIButton) {
  12. alertSelection(button.title(for: .normal) ?? "None")
  13. }
  14. func alert(item: ActionSheetItem) {
  15. alert(items: [item])
  16. }
  17. func alert(items: [ActionSheetItem]) {
  18. let items = items.filter { !($0 is ActionSheetButton) }
  19. guard items.count > 0 else { return }
  20. alertSelection(items.map { $0.title }.joined(separator: " + "))
  21. }
  22. func alert(items: [MyCollectionViewCell.Item]) {
  23. guard items.count > 0 else { return }
  24. alertSelection(items.map { $0.title }.joined(separator: " + "))
  25. }
  26. func alert(title: String?, message: String) {
  27. let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
  28. let ok = UIAlertAction(title: "OK", style: .default, handler: nil)
  29. alert.addAction(ok)
  30. present(alert, animated: true, completion: nil)
  31. }
  32. func alertSelection(_ value: String) {
  33. self.alert(title: "You selected:", message: value)
  34. }
  35. }