DestructiveActionSheet.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // DestructiveActionSheet.swift
  3. // SheeeeeeeeetExample
  4. //
  5. // Created by Jonas Ullström on 2018-03-16.
  6. // Copyright © 2018 Jonas Ullström. All rights reserved.
  7. //
  8. /*
  9. These extensions provides action sheets with functions that
  10. are shared by all example action sheets.
  11. */
  12. import Sheeeeeeeeet
  13. class DestructiveActionSheet: ActionSheet {
  14. init(options: [FoodOption], action: @escaping ([ActionSheetItem]) -> ()) {
  15. let items = DestructiveActionSheet.items(for: options)
  16. super.init(items: items) { sheet, item in
  17. guard item.isOkButton else { return }
  18. let items = sheet.items.compactMap { $0 as? ActionSheetSelectItem }
  19. action(items.filter { $0.isSelected })
  20. }
  21. }
  22. required init?(coder aDecoder: NSCoder) {
  23. super.init(coder: aDecoder)
  24. }
  25. }
  26. private extension DestructiveActionSheet {
  27. static func items(for options: [FoodOption]) -> [ActionSheetItem] {
  28. let titleItem = ActionSheetTitle(title: "Remove Payment Options")
  29. let image = UIImage(named: "ic_credit_card")
  30. let visaTitle = "Visa **** **** **** 4321"
  31. let visa = ActionSheetMultiSelectItem(title: visaTitle, isSelected: false, value: "visa", image: image)
  32. let masterTitle = "MasterCard **** **** **** 9876"
  33. let master = ActionSheetMultiSelectItem(title: masterTitle, isSelected: false, value: "master", image: image)
  34. let removeButton = ActionSheetDangerButton(title: "Remove")
  35. return [titleItem, visa, master, cancelButton, removeButton]
  36. }
  37. }