diff --git a/README.md b/README.md index 3057630a..3e7675d1 100755 --- a/README.md +++ b/README.md @@ -215,6 +215,13 @@ alert.addDatePicker(mode: .dateAndTime, date: date, minimumDate: minDate, maximu alert.addAction(title: "OK", style: .cancel) alert.show() ``` +Get the date in your action handler. +```swift +alert.addAction(title: "OK", style: .cancel) { _ in + let date = alert.dateFromDatePicker() + // action with selected date +} +``` ## PickerView @@ -242,6 +249,13 @@ alert.addPickerView(values: pickerViewValues, initialSelection: pickerViewSelect alert.addAction(title: "Done", style: .cancel) alert.show() ``` +Get the picker in your action handler. +```swift +alert.addAction(title: "Done", style: .cancel) { + let picker = alert.pickerView() + // action with the picker view +} +``` ## Locale Pickers diff --git a/Source/Pickers/Date/DatePickerViewController.swift b/Source/Pickers/Date/DatePickerViewController.swift index ac6bf256..77bf8ed9 100644 --- a/Source/Pickers/Date/DatePickerViewController.swift +++ b/Source/Pickers/Date/DatePickerViewController.swift @@ -15,6 +15,18 @@ extension UIAlertController { let datePicker = DatePickerViewController(mode: mode, date: date, minimumDate: minimumDate, maximumDate: maximumDate, action: action) set(vc: datePicker, height: 217) } + + /// Returns the date from the datePicker + /// Author: Jahid Hasan Polash + /// InfancyIT + /// jahidhasanpolash@gmail.com + func dateFromDatePicker() -> Date? { + guard let datePickerVC = value(forKey: "contentViewController") as? DatePickerViewController + else { + return nil + } + return datePickerVC.datePicker.date + } } final class DatePickerViewController: UIViewController { diff --git a/Source/Pickers/PickerView/PickerViewViewController.swift b/Source/Pickers/PickerView/PickerViewViewController.swift index 2e5c32a0..c1f56171 100644 --- a/Source/Pickers/PickerView/PickerViewViewController.swift +++ b/Source/Pickers/PickerView/PickerViewViewController.swift @@ -12,6 +12,18 @@ extension UIAlertController { let pickerView = PickerViewViewController(values: values, initialSelection: initialSelection, action: action) set(vc: pickerView, height: 216) } + + /// Returns the picker view itself to extract data or index from it + /// Author: Jahid Hasan Polash + /// InfancyIT + /// jahidhasanpolash@gmail.com + func pickerView() -> UIPickerView? { + guard let pickerViewController = value(forKey: "contentViewController") as? PickerViewViewController + else { + return nil + } + return pickerViewController.pickerView + } } final class PickerViewViewController: UIViewController {