LinkActionSheet.swift 881 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // LinkActionSheet.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. import Sheeeeeeeeet
  9. class LinkActionSheet: ActionSheet {
  10. init(options: [FoodOption], action: @escaping ([ActionSheetItem]) -> ()) {
  11. let items = LinkActionSheet.items(for: options)
  12. super.init(items: items) { _, item in
  13. if item.value == nil { return }
  14. action([item])
  15. }
  16. }
  17. required init?(coder aDecoder: NSCoder) {
  18. super.init(coder: aDecoder)
  19. }
  20. }
  21. private extension LinkActionSheet {
  22. static func items(for options: [FoodOption]) -> [ActionSheetItem] {
  23. var items = options.map { $0.linkItem() }
  24. items.insert(titleItem(title: standardTitle), at: 0)
  25. items.append(cancelButton)
  26. return items
  27. }
  28. }