Skip to content

Commit

Permalink
Added set actions function
Browse files Browse the repository at this point in the history
  • Loading branch information
sgr-ksmt committed Jun 24, 2017
1 parent 1b69904 commit eb17e81
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
21 changes: 19 additions & 2 deletions Demo/Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ class ViewController: UIViewController {
private func showActionSheet(anchorView: UIView) {
Alertift.actionSheet(message: "Which food do you like?", anchorView: anchorView)
.action(.default("🍣"))
.action(.default("🍎"))
.action(.default("🍖"))
.actions([.default("🍎"), .default("🍖")], handler: { (action, index) in
print("!!!!! action: \(action), index: \(index)")
})
.action(.default("🍅"))
.action(.cancel("None of them"))
.finally { action, index in
Expand All @@ -118,6 +119,22 @@ class ViewController: UIViewController {
.show()
}
.show()

// Alertift.actionSheet(message: "Which food do you like?", anchorView: anchorView)
// .action(.default("🍣"))
// .action(.default("🍎"))
// .action(.default("🍖"))
// .action(.default("🍅"))
// .action(.cancel("None of them"))
// .finally { action, index in
// if action.style == .cancel {
// return
// }
// Alertift.alert(message: "\(index). \(action.title!)")
// .action(.default("OK"))
// .show()
// }
// .show()
}
}

11 changes: 11 additions & 0 deletions Sources/ActionSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ extension Alertift {
return self
}

/// Add actions to Alert
///
/// - Parameters:
/// - actions: Alert actions.
/// - handler: The block to execute after this action performed.
/// - Returns: Myself
public func actions(_ actions: [Alertift.Action], handler: @escaping Handler = { _ in }) -> Self {
actions.forEach { _ = action($0, handler: handler) }
return self
}

/// Add finally handler.
///
/// - Parameter handler: The handler to execute after either alert selected.
Expand Down
13 changes: 12 additions & 1 deletion Sources/Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ extension Alertift {
addActionToAlertController(buildAlertAction(action, handler: merge(_alertController.actionWithTextFieldsHandler, handler)), isPreferred: isPreferred)
return self
}


/// Add actions to Alert
///
/// - Parameters:
/// - actions: Alert actions.
/// - handler: The block to execute after this action performed.
/// - Returns: Myself
public func actions(_ actions: [Alertift.Action], handler: @escaping Handler = { _ in }) -> Self {
actions.forEach { _ = action($0, handler: handler) }
return self
}

/// Add finally handler.
///
/// - Parameter handler: The handler to execute after either alert selected.
Expand Down

0 comments on commit eb17e81

Please sign in to comment.