ViewController+Alerts.swift 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. /*
  9. These extensions are only used by the example app, to alert
  10. which options a user selects in the example action sheets.
  11. */
  12. import UIKit
  13. import Sheeeeeeeeet
  14. extension ViewController {
  15. func alert(button: UIButton) {
  16. alertSelection(button.title(for: .normal) ?? "None")
  17. }
  18. func alert(item: ActionSheetItem) {
  19. alert(items: [item])
  20. }
  21. func alert(items: [ActionSheetItem]) {
  22. let items = items.filter { !($0 is ActionSheetButton) }
  23. guard items.count > 0 else { return }
  24. alertSelection(items.map { $0.title }.joined(separator: " + "))
  25. }
  26. func alert(items: [MyCollectionViewCell.Item]) {
  27. guard items.count > 0 else { return }
  28. alertSelection(items.map { $0.title }.joined(separator: " + "))
  29. }
  30. func alert(title: String?, message: String) {
  31. let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
  32. let ok = UIAlertAction(title: "OK", style: .default, handler: nil)
  33. alert.addAction(ok)
  34. present(alert, animated: true, completion: nil)
  35. }
  36. func alertSelection(_ value: String) {
  37. self.alert(title: "You selected:", message: value)
  38. }
  39. }