-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathAlertControllers.swift
55 lines (46 loc) · 1.62 KB
/
AlertControllers.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import Foundation
import UIKit
import Eureka
extension UIAlertController {
static func duplicateBook(goToExistingBook: @escaping () -> Void, cancel: @escaping () -> Void) -> UIAlertController {
let alert = UIAlertController(title: "Book Already Added", message: "A book with the same ISBN or Google Books ID has already been added to your reading list.", preferredStyle: .alert)
// "Go To Existing Book" option - dismiss the provided ViewController (if there is one), and then simulate the book selection
alert.addAction(UIAlertAction(title: "Go To Existing Book", style: .default) { _ in
goToExistingBook()
})
// "Cancel" should just envoke the callback
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel) { _ in
cancel()
})
return alert
}
}
enum Orderable {
case book(BookReadState)
case list(List)
func supports(_ sort: BookSort) -> Bool {
switch self {
case let .book(readState):
return sort.supports(readState)
case .list:
return sort.supportsListSorting
}
}
func getSort() -> BookSort {
switch self {
case let .book(readState):
return BookSort.byReadState[readState]!
case let .list(list):
return list.order
}
}
func setSort(_ order: BookSort) {
switch self {
case let .book(readState):
BookSort.byReadState[readState] = order
case let .list(list):
list.order = order
list.managedObjectContext!.saveAndLogIfErrored()
}
}
}