Created
October 8, 2015 23:29
-
-
Save joshavant/5e686636d267ca88f3a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func alertControllerToSelectContactMethod() -> UIAlertController { | |
| let controller = UIAlertController(title: "How do you want to contact \(firstName.value)?", message: "", preferredStyle: .ActionSheet) | |
| let methodsAndHandlers = contactMethodsAndHandlers() | |
| if (methodsAndHandlers.count == 0) { | |
| let action = UIAlertAction(title: NSLocalizedString("No Contact Info Found", comment: ""), style: .Default, handler: nil) | |
| action.enabled = false | |
| controller.addAction(action) | |
| controller.addAction(UIAlertAction(title: NSLocalizedString("Ok", comment: ""), style: .Default, handler: userSelectionCanceled)) | |
| } else { | |
| methodsAndHandlers.forEach { | |
| (methodAndHandler: (method: String, handler: ((UIAlertAction) -> Void))) in | |
| controller.addAction(UIAlertAction(title: methodAndHandler.method, style: .Default, handler: methodAndHandler.handler)) | |
| } | |
| controller.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .Cancel, handler: userSelectionCanceled)) | |
| } | |
| return controller | |
| } | |
| func contactMethodsAndHandlers() -> Array<(String, ((UIAlertAction) -> Void))> { | |
| var methods: Array<(String, ((UIAlertAction) -> Void))> = [] | |
| phoneNumbers.forEach { | |
| number in | |
| methods.append((number, userSelectedPhoneNumber)) | |
| } | |
| if(messageUIFactory.canSendMail()) { | |
| emails.forEach { | |
| email in | |
| methods.append((email, userSelectedEmail)) | |
| } | |
| } | |
| return methods | |
| } | |
| // MARK: UIAlertAction Handlers | |
| func userSelectedPhoneNumber(action: UIAlertAction!) { | |
| // do things... | |
| } | |
| func userSelectedEmail(action: UIAlertAction!) { | |
| // do things... | |
| } | |
| func userSelectionCanceled(action: UIAlertAction!) { | |
| // do things... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment