Prerequisites for iOS development with Swift

Côme Chevallier
4 min readJun 12, 2017

--

Where it all started. Mac + Xcode + Terminal + Cocoapods.

Basically us right now.

NB: Have you read this important piece first?

Download Xcode from the Appstore

You need to write code somewhere on your Mac to tell iPhones/iPads you are programming an app for what to do and that somewhere is Xcode, Apple’s IDE (Integrated Development Environment).

Xcode is a suite of software development tools. Basically with it you will, among other things:

  • write source code that gives instructions as to what your app should do. Because a machine like an iPhone or iPad can only execute “low-level” machine code (suite of 1 and 0) that makes zero sense for a human being, several abstractions exist on top of it to make it intelligible; the top-most in this case being the “high-level” language Swift (in which your source code is written).
  • “build” your app: Xcode will then translate (compile) your source code all the way down to machine code so that your app (program) can be executed by a device.
  • debug your code, thanks to “breakpoints” (used to pause the program’s execution) and “console logs” (used to display information along the program’s execution) to find and solve bugs or errors.

Terminal

When you navigate or launch apps on your Mac, you usually do so through a Graphical User Interface: you click on app icons, look for folders in Finder, etc.

The other way is to use the Terminal, which is a command line tool. You directly type instructions for your Mac in a certain language (Bash in this case).

To prompt a Terminal, hit ⌘+space and type in “Terminal”, then press enter/return. We will use it to install Cocoapods.

Cocoapods

This is a dependency manager for Swift (and Objective-C) app projects.

In virtually every more-than-ultra-basic project, you will need to install some “libraries/frameworks” because you do not want to reinvent the wheel every time and write everything your app should do all by yourself. Libraries and frameworks are basically source code that do certain things. These are general-purpose functionalities that have been built over the years by developers who open-sourced their work and which are common to a lot of apps, like downloading and caching (i.e. storing) a picture on an iPhone/iPad device.

Cocoapods provides a clean and simple way to manage all these “dependencies” (i.e. “libraries/frameworks”).

Go to the terminal and paste the following Bash command sudo gem install cocoapods . The sudo makes you a “super-user”, who can call any command: here we installa Ruby gem named cocoapods . A gem is a program written in Ruby (another programming language).

Wrapping Up

Open Xcode and create a new single-view application in the iOS tab. Fill-in the product name information and choose your organization name and identifier. Make sure your organization identifier is of the form “com.yourorganization.yourproductname”. This is the way Apple identifies your app as unique with the subsequent bundle ID (more here) — better be coherent. Save the project on your Desktop.

Immediately after the project is created, close Xcode and go back to the Terminal. Type in cd , which will make sure that you are brought back to the root folder of your computer, then cd Desktop/ . The “change directory” command cd allows you to navigate between folders in the terminal, the same you would navigate in the GUI by clicking on folders.

Now that you are on your Desktop in the Terminal, go to your app’s project root folder by typing cd YourProjectNameFolder/ and replacing the second argument with whatever you chose. You are now in your project’s folder and if your type in thels command, you should see a YourProject.xcodeproj file.

Now type in the pod init command to create a Podfile in this directory where you will specify which libraries/frameworks you want to install. For now, we won’t be installing any (i.e. we won’t be modifying the Podfile yet) so simply type pod install . A message in the Terminal should have let you know that from now on, you should only open YourProject.xcworkspace and work from here. A workspace is simply a collection of projects, which will be constituted of your app and all the frameworks and libraries installed via Cocoapods.

Conclusion

Through these prerequisites for iOS development, you have:

  • installed Xcode, Apple’s IDE, and learned that you will code your app in it with the Swift language
  • learned that you won’t have to reinvent the wheel for a lot of stuff when doing so thanks to libraries and frameworks, which are pieces of source code developed by people that implement common general functionalities
  • learned that you will install these libraries and frameworks with the help of Cocoapods, a powerful dependency manager for Swift projects, by modifiying the Podfile in your project’s root directory

Bonus

I personally use iTerm2 in lieu of Apple’s Terminal for some of the few reasons outlined here. Some of them are outdated. The first terminal I opened was an iTerm2, and mine now has a few customized settings so I stick to it. In the end, it doesn’t matter which one you choose if you use it to only navigate between folders like we did here.

--

--