The current project: A complete rewrite of the good old CompareMe app in Apples new programming language Swift. So, there are some insights & code snippets of a Swift ActionSheet example I want to share with the interested iOS developer community.

Today, let’s create some action sheets to open websites, twitter profiles in the native twitter app on the iOS device or create a eMail on the device. The Swift code is tested on Xcode 6.1 GM with iOS 8.1 on OS X Yosemite 10.10 GM.

If you present your alert as a UIAlertControllerStyle.ActionSheet, then be sure to include the popoverController.sourceView & popoverController.sourceRect. Otherwise your app will terminate on a big screen device like the iPad.On those devices, the ActionSheet is not displayed as a modal view, which covers the whole screen like on iPhone devices. Here the ActionSheet is presented as a popup besides the element, which created the ActionSheet.

Compose a new email with passing a “mailto:…@…” url is the easiest way to accomplish that goal. But be aware, that the user is switching to the Mail program to compose that mail. If the user sends or cancels the form, the user will not be directed back to your application. So if you want the user to stay in your app, or if you want to define more parameters, like the subject or body of the email, then you have to use MFMailComposeViewController … But that’s an other post 😉

Pin It on Pinterest

Share This