Member-only story
How to Call, Message, and Email in Swift
In as few as two lines of code

Hello iOS developers! Today we’re going to learn how to call, send a text message, and send email using Swift.
I assume that you have a basic understanding of Swift syntax and have Xcode installed on your computer. Let’s get started!
Project Setup
First, let’s create a new project and name it “CallMessageEmail App.” When creating a new project, select “Swift” for “Language” and “Storyboard” for “UI Interface”—it’s easier for developing iOS apps.
Your initial project should look like this:

CallMessageEmail
App.Now, we design our storyboard by drag-and-dropping the buttons and labels. Head over to the Storyboard and create three buttons. Label them “Call Me!!”, “Message Me!!” and “Email Me!!”, or whatever else you prefer.
Your design should look basically like this:

After designing the initial wireframe, we have to drag in the ViewController.swift
file. To drag the buttons, click “Control” and drag to the ViewController.swift
file. While naming the functions, you can choose whatever names you feel comfortable with. I’d make them as simple as possible, i.e. callMeButton
, messageMeButton
and emailMeButton
.
Your code should look like this:

Now, let’s run the app. You can see the button, but it’s not working yet. We’re going to code each button in the next step.
In order to send either an email or message, we have to import the MessageUI
library. Do this by typing import MessageUI
at the top of the file after import UIKit
. Everyone knows what UIKit is for.
MessageUI
will make life a lot easier while sending the messages and emails.