Xcode > File > New > Project
How to configure your environment for productivity
It’s easy to create a new Xcode project, all you have to do is the following:
- Open Xcode
- Click File on the menu bar
- Finally, click New then choose Project on the menu options
Or you could just use ⌘+⇧+N on your keyboard.
Now, why am I writing about something as basic as this? Well, the reason here is that the Xcode’s stock Single View Application project lacks a few things that can help improve your productivity as a developer. 💻 ✨
The stock Xcode project contains the following:
- A git repository — This appears if you’ve checked the Create Git repository on my Mac option. I always check this option.
- The .xcodeproj file — You use this to open Xcode.
- The project folder— This folder contains the code you’ll be working on for a project.
While the stock project is already good to go for application development, it still lacks a few things:
- .gitignore
- Dependency Manager
- Code Linter and Formatter
- Other Dependencies, Extensions, and Softwares
Now that I’ve enumerated the things I need in my project, let’s start by explaining each of them starting with the .gitignore.
.gitignore
This file is one of the most important objects to think of at the beginning of your project. It determines which files and folders are to be ignored when adding files to your git repository.
If you accidentally a wrong file or folder, over-time your project’s file size could bloat up to at least a gigabyte. Trust me you wouldn’t want that to happen.®
Adding a .gitignore file is easy, you can do this in a lot of ways. In my case, I use the command line. 👌
Drag a folder straight to the Terminal window to show get to the project directory. Use the touch command to create the .gitignore file.
touch .gitignore
After that, add the .gitignore file on your Xcode project. 📁
Now some of you might ask me, why didn’t I just use Xcode to create the .gitignore file? That’s because I’ll be heavily using the Terminal for the other steps after this, might as well start from here right? 🤷♂
Finally, for the contents of the .gitignore file, let’s get a template from gitignore.io, below is a template.
Dependency Manager
In a previous article, I mentioned that “Modern application development is reliant on code which is written by other people”. You can do this by using dependencies/libraries.
A Dependency Manager is needed to integrate dependencies. There are a few options we can choose from for iOS, this includes Cocoapods, Carthage, and Swift Package Manager. Personally I use Cocoapods. To add this to the project you once again need to use the terminal.
For a list of awesome libraries you can use, here are a few links you can look at
Code Linter and Formatter
Out of the box, Xcode already comes with its own linter, though it’s powerful in its own merit, for me it’s not enough, one of the reasons why is because it is not customizable.
There’s no better way to write better code than to have a linter telling you your code isn’t enough. 😢 Adding a linter and formatter helps with that.
- Linters check and flag your code for issues, misspellings, and bugs.
- Formatters on the other hand automatically correct a few of these misspellings, issues, and help construct your code better.
Adding both of them to the project is as easy as adding new dependencies through Cocoapods. These dependencies are SwiftLint and SwiftFormat.
Next we create the config files to be able to customize the lint and formatter rules.
touch .swiftlint.auto.yml
touch .swiftlint.yml
touch .swiftformat
Here are the configurations I use, you may copy them if you like.
- .swiftlint.auto.yml — Format rules for SwiftLint
- .swiftformat — Format rules for the more powerful formatter SwiftFormat
- .swiftlint.yml — Lint rules for SwiftLint
This won’t automagically work just because we added these libraries to our project. We still need to add a new Run Script Build Phase to the Xcode project to make sure these instructions will be run.
Inside that Run Script Phase, add the snippet below.
Now add some bad code and see the magic happen.
Here’s a sample project with the discussed tools above:
Other Dependencies, Extensions, and Softwares
Here are some of the things I generally use for most, if not all, of my projects.
SwifterSwift
SwifterSwift is a collection of over 500 native Swift extensions, with handy methods, syntactic sugar, and performance improvements for a wide range of primitive data types, UIKit and Cocoa classes –over 500 in 1– for iOS, macOS, tvOS, watchOS, and Linux.
R.swift
R.swift helps make it easier for developers to access certain resources within our codebase. So instead of using strings, we are now leveraging autocompleted type-safe objects.
Quicktype
Quicktype can automagically generate models for you from JSON. There are extensions you can install on Xcode, VSCode, Command-Line, and a standalone app you may use.
Fastlane
Fastlane is the best Command-Line tool you can use to create CI/CD pipelines. If you choose to use this, you won’t have to think about CI server compatibility because most CI servers are compatible with Fastlane.
Bitrise
Bitrise is a CI/CD Platform as a Service for mobile development. I learned how to create CI/CD pipelines for mobile applications thanks to Bitrise. Bitrise’s dashboard helped me understand and visualize what those .yml files do. Fastlane is also compatible with this service.
If you’re reading this, then you’ve reached the end. Cheers! 🍻
If you have any comments, suggestions, questions, or ideas for new blog posts leave a comment down below. 👇👇
Thank you for taking the time on reading my article. 🎉