My brother recently purchased a Macbook Pro and has decided to start learning how to code for iOS (and potentially other platforms as well). There has never been a better time to get into software development, especially iOS development. I’ve been in the iOS space since it’s inception and wanted to put together a guide for beginners covering various topics, tips, and resources that I wish I had early in my career.
DISCLAIMER: This should by no means be a definitive guide. I have done my best to encompass information I feel will be relevant to those starting iOS development. I encourage and implore you, the reader, to seek out additional sources of information as you embark on your development journey.
Table Of Contents
- Getting Started
- Swift & Objective-C
- Version Control
- Dependency Management
- Build Something Great
- Further Reading
In order to develop for iOS there are few things you’ll need to get started. This guide makes no assumptions on the knowledge or skill level of the reader. Programming is hard. If you get frustrated take a break. Don’t be afraid to reach out to others for help.
What This Guide Isn’t
This guide isn’t going to cover the nuts and bolts of how to program in Swift or for iOS. There are plenty of guides out there for that already. Rather, it will cover the tools and technologies that you will likely need to become a successful iOS developer.
|API||API stands for application programming interface. Generally speaking, an API is a set of protocols, functions, and interfaces for building software. When you interface with a web service you are probably talking to the web services through a RESTful API. When you are developing software UIKit you are using the UIKit API, and so on.|
|SDK||SDK stands for software development kit and is typically a set of tools and technologies that allow you to create applications, frameworks, or libraries. Different environments require different SDKs. For example when developing iOS applications you will likely make extensive use of UIKit. When developing Mac applications you will likely make extensive use of AppKit.|
|REST||REST stands for Representational State Transfer. (It is sometimes spelled “ReST”.) It relies on a stateless, client-server, cacheable communications protocol – and in virtually all cases, the HTTP protocol is used. REST is an architecture style for designing networked applications. (Credit: elkstein.org)|
Xcode is an integrated development environment (IDE) that enables you to develop software for Apple platforms. Think of Xcode as an analogue to Microsoft Word or Excel. You can download Xcode here: https://developer.apple.com/xcode/download/. I recommend downloading the GM version of Xcode unless you have a good reason to install a beta.
After downloading and installing Xcode you will need to perform a few additional step, mainly installing additional simulators and documentation. To install additional simulators and documentation perform the following steps:
- Tap the Xcode application name in the menu bar. This should expose a menu.
- Tap the
Preferencesoption. This will open a preferences window.
- Tap the
Downloadstab. You should see a list of items.
- Download simulators. I recommend installing at least 1 simulator from the prior major iOS version. For example if the latest version is iOS 9, make sure you have at least one iOS 8 simulator downloaded.
- Download all relevant documentation. I recommend grabbing everything.
- Make sure
Check for and install updates automaticallyis checked.
Organizing your project files is an oft overlooked but critically important task. An organized Xcode project makes it easier to reason about your program and easier to find what you’re looking for. A good starting point for project structure will probably look something like this:
├─ Models ├─ Extensions ├─ Views ├─ View Controllers ├─ Static
I also think it’s a good idea that your project structure mirror your folder structure. There is a great utilty that can automatically do this for you called Synx.
First, create them as groups (little yellow “folders”) within the group with your project’s name in Xcode’s Project Navigator. Then, for each of the groups, link them to an actual directory in your project path by opening their File Inspector on the right, hitting the little gray folder icon, and creating a new subfolder with the name of the group in your project directory.
Xcode comes with simulators for the latest version of iOS (iOS 9.1 at the time of writing). Simulators allow you to test and deploy your app right on your computer instead of having to deploy directly to a device. This is very useful for rapid iteration but should not be considered a replacement for on-device testing as there is a delta in behavior and functionality between iOS simulators and actual devices.
Apple has a treasure trove of documentation available for iOS, tvOS, watchOS, OS X and more. Most of this is not bundled with Xcode directly.
Swift & Objective-C
Swift is the future of programming for Apple platforms and potentially many other platforms due to being open source. You should focus the vast majority of your efforts on learning Swift. There are a veritable wealth of learning resources:
The Swift Programming Language This is Apple’s official Swift reference and an invaluable resource. I recommend reading this guide cover-to-cover, taking your time on areas that confuse you.
App Code - Learning Swift is a great starter resource. I recommend following along with Xcode Playgrounds.
Developing iOS 8 Apps With Swift While a little old the material quality is top notch.
Objective-C used to be the primary programming language used to write software for Apple platforms. This is no longer the case with the introduction of Swift in 2014. I believe it’s still important to have a good grasp of the language since you many good open source projects are still written in Objective-C and you will likely be maintaining an Objective-C codebase at some point in your career.
One of the hallmark features of Objective-C is its dynamic runtime. Nikolai Ruhe describes this very succinctly on StackOverflow:
Objective-C decides which method implementation to call right before doing so (during runtime). The idea is that the connection between the name of a method and the implementation is dynamic. C++ for example does this during compile time. For example:
id object = @"1"; int i = [object intValue]; object = @1; i = [object intValue];
In this example the
intValuemessage is first sent to an instance of NSString and then to an
NSNumber. The code emitted by the compiler is identical for both calls–in fact the compiler does not even know to which kind of object it’s sending messages to (as the type is id).
The runtime decides which implementation to call to extract an int value from a string or an
A dynamic runtime decides which method to call just before doing so.
Writing Clean Code
Writing clear, concise, expressive code is of paramount importance. Code is meant to be executed by the computer in order to accomplish a goal but even more importantly code is meant to be read. Endeavor to write code that is easily comprehended and be wary of code that purports to be clever but is hard to understand.
To that end I recommend you adopt a style guide when writing code. A style guide is a set of standards for desiging and writing software. Some languages such as Go provide a standard style guide and automatic enforcement, Swift and Objective-C unfortunately do not have this.
There are many style guides available for both Swift and Objective-C and the ones listed below share many similarities. Pick one style guide and stick with it. As you continue programming your preferences will evolve and you may switch, and that’s OK.
Here are some style guides that I think are worth reading:
Swift Community Best Practices: Community created guide detailing Swift best practices. Lots of good stuff here.
Raywenderlich.com Swift Style Guide: The official Swift style guide for raywenderlich.com.
GitHub Swift Style Guide: GitHub’s official Swift style guide.
New York Times Objective-C Style Guide: You probably won’t be writing much Objective-C but when you do this is the definitive guide for doing so.
Playgrounds are an amazing feature of Xcode that allow you to play. From Apple:
A playground is an interactive Swift coding environment that evaluates each statement and displays results as updates are made, without the need to compile and run a project.
Use playgrounds to learn and explore Swift, prototype parts of your app, and create learning environments for others. The interactive Swift environment lets you experiment with algorithms, explore system APIs, and even create custom views, all without the need to create a project.
Share your learning with others by adding notes and guidance using rich comments. Create an explorable learning environment by grouping related concepts into pages and adding navigation.
You should be using playgrounds extensively on your iOS development journey for protoyping, learning, and much more.
Version control, what is it? Git has a good overview: > Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. For the examples in this book you will use software source code as the files being version controlled, though in reality you can do this with nearly any type of file on a computer.
You need to understand version control and how to use it effectively. For the first 2 years of my software career I didn’t even know what version control was. My backup solution consisted of my zipping up my work folder maybe once or twice a week. If something went wrong, and it usually did, I was left with stale backups or at the mercy of undo in my coder editor. You don’t want to do that.
There are many version control systems (Git, SVN, Mercurial, etc). I recommend sticking with Git since it works pretty well and it’s what most of the iOS development community is using. Here’s a list of several popular hosted Git services:
GitHub is most popular source control option and the choice for the vast majority of open source software, especially Swift/Objective-C. As the name implies GitHub is focused on Git. GitHub is free for public repositories and charges based on the number of private repositories you host.
BitBucket is another popular source control option. BitBucket charges by user instead of repository so you can have an unlimited number of private repos which can be very useful when starting out.
Beanstalk is another paid option I personally used for several years. What sets Beanstalk apart are it’s deployment tools.
There are 2 ways to interact with Git, through the command line or through a Git client. Both have their uses. If you want to checkout Alamofire, a popular HTTP networking library you would perform the following terminal command:
git clone https://github.com/Alamofire/Alamofire.git
This would checkout a copy of Alamofire onto your machine. GitHub has a great list of resources for learning Git. Learn Git well and you will be a wizard among your peers.
Here are some popular Git clients for OS X:
GitBox ($14.99) is a UI wrapper around Git that provides a barebones abstraction away from Git. I use this in my day-to-day in conjunction with the command line tools.
GitUp (FREE) is a fancy Git client for OS X that features a nifty visual view and very fast workflows for a variety of common Git operations.
SourceTree (FREE) is a comprehensive UI client that exposes virtually all of Git capabilities. SourceTree is a heavy client but comes chock fully of virtualyl any kind of Git functionality you’ll probably ever need.
Testing is arguably the single most important topic in this guide and the secret weapon of many top-notch developers.
Why You Should Test
Testing helps ensure the software you’ve created works how you assumed it should. Many developers are hostile to unit testing until they realize that with the proper tests in place they can refactor their code without fear of introducing bugs.
Testing, especially Test Driven Development (TDD) changes how you write code. Testable code is decoupled, modular, and composable. Writing code in this fashion will grant you extreme flexibility and make testing a breeze.
Conversely, most software that is written without tests is tightly coupled, monolothic and not at all composable. Because of this retrofitting an existing project with proper test coverage is usually extremely difficult.
Manual testing is the most basic form of testing. You implement a feature and then manually test that it works. All developers practice manual testing in one form or another. The challenge with manual testing is that it’s manual. As your app grows in complexity the surface area for testing grows, usually in an exponential fashion.
Believe it or not a majority of developers still exclusively test their software via manual testing.
making manual testing need to perform grows and the potential for you to miss sometin
SearchSoftwareQuality defines unit testing pretty well:
Unit testing is a software development process in which the smallest testable parts of an application, called units, are individually and independently scrutinized for proper operation. Unit testing is often automated but it can also be done manually.
Unit tests are usually run by your IDE (Xcode) but can also be automatically executed on a build machine,
Integration testing is very much like unit testing but instead of testing individual units you are testing systems. Integration testing can be performed manually using test plans or done in an automated fashion.
A good example of integration testing for iOS is testing user flows in your application. Say your application has a login component which takes the user to the home screen in your application after a successful login. You manual or automated integration test would login using pre-defined credentials and verify that the user arrived at the correct destination.
Another important and oft overlooked area of integration testing is integration with 3rd party APIs. Many apps rely heavily on integrating with 3rd party API endpoints. Validating the behavior and API contract of 3rd party endpoints of SDKs will save you much heart-ache.
ThoughtWorks has a good description and overview of continuous:
Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.
By integrating regularly, you can detect errors quickly, and locate them more easily.
A typical iOS continuous integration workflow looks like this:
- Developer checks in code to their branch or fork
- Build server sees that a new commit is availabe
- Build server builds developer fork or branch, verifies that branch builds successfully
- Build server runs all automated unit and integration tests against code, reporting on successful and failed tests
- Build server marks the developers fork or branch as ready for integration into the main branch
In a web based, or back-end world continuous integration can help developers deploy to production multiple times per day. Because the App Store has an approval process deploying multiple times per day on iOS is not feasible for production builds.
Since you’re just starting out in iOS development continuous integration is not that important right now. However, once you join a company or start iOS consulting it should become a vital part of your workflow.
Test Driven Development
Test driven development (TDD) is the art of writing software through continuous feedback which is provided by your tests. The TDD cycle looks like this:
- RED: You write an automated test that asserts the desired behavior or functionality.
- GREEN: You write the minimum amount of code to make the test pass.
- REFACTOR: You refactor the new code to incorporate best practices and adhere to your programming standards.
Test driven development encourages modular, composable software architecture. In order to practise test driven development well you have no choice to structure your code in a certain way.
When you first start practicing TDD you will feel very frustrated. You will feel that you are much slower practising TDD. This is normal, don’t give up, persevere! After a few days (or weeks) you will be back up to your previous speed.
The real benefit of test driven development is not in creation of the initial program but of the maintenance and extension of your codebase. Because you practise TDD your code base will have 90-100% code coverage through your tests. This means that you can refactor ruthlessly, add new features, then run your tests to see what broke. If you didn’t have that test coverage you wouldn’t know what broke without tedious manual testing.
Here are some great testing resoures that I hope you will find useful:
Using Unit Tests: Apple’s official guide for unit testing on iOS
Writing Tests with Swift: Another great apple resource reviewing Swift testing. Highly recommended.
UI Testing In Xcode: Apple WWDC 2015 video reviewing UI testing. Highly recommended. The maturity level for UI testing on iOS is head and shoulders above just about every other development platform.
Test-Driven iOS Development (Book): This book covers the basics of testing in iOS and has many techniques that you will be able to apply.
Introduction to Testing on iOS (Blog): While this tutorial is a little dated, the mechanics are largely the same.
iOS Testing In 2015 (Blog): Excellent resource reviewing the state of iOS testing along with many refernces to helpful testing tools.
Dependency management is the practice managing dependencies in your software. It’s important to note that there are multiple types of dependencies such as images, videos, and 3rd party code or libraries.
When people talk about dependency management in the context of software it’s nearly always talking about managing 3rd party code or libraries. There are many strategies for managing dependencies, we’ll talk about a few of them here.
Depdency management is somewhat of a hot topic with ioS developers. Many have strong opinions about which technology or approach to leverage or adopt. My advice to those starting out is to find something that works for you. As you grow as a developer your dependency management strategies and approaches will evolve. This is good thing!
Vendoring is the moving of all 3rd party code into a
vendor/ directory. This is convenient and sometimes necessary but should be avoided if at all possible for the following reasons:
- You have to manually update all vendored dependencies. This is a pain.
- You are losing all dependency history information
- It’s an inefficient use of space
- It’s very difficult to later ascertain which version of the dependency code you copied into your vendor folder
Are there legitimate reasons for vendoring code? Sure, but I leave it as an exercise to the reader to determine what those reasons are. Thankfully there are good alternatives to vendoring.
CocoaPods is a dependency manager for Swift and Objective-C projects. CocoaPods was the first widely used dependency management solution on iOS. Prior to CocoaPods we vendored code and leveraged git submodules – those were dark days.
CocoaPods is relatively easy to use and has well over ten thousand libraries available and searchable on cocoapods.org. The tutorials and getting started guides on their website are also top-notch.
Carthage professes to be a simple, decentralized dependency manager. Carthage differs from CocoaPods in two primary ways:
- It’s decentralized. There is no central list of Carthage compatible projects.
- Carthage doesn’t mess with your Xcode project files at all. Carthage will build frameworks built the responsibility of integrating these frameworks is up to you, the developer.
Build Something Great
One of the best ways to learn something, especially programming, is to have a goal. It doesn’t have to be a billion dollar app idea or even original but it should be something that you are passionate about. Here a fews that I have found helpful to maintain momentum:
Learn Something New
Make a point to learn something new every day that will help you achieve your goal. The road to success is built upon steady, incremental progress.
Write Code Every Day
Write code every single day. This is important. You don’t have to implement an entire feature but make your best effort. The road to success is built upon steady, incremental progress.
Track Your Progress
Keep a log of what you accomplished or tried to accomplish each day. At the end of each day note what you want to try and accomplish tomorrow. Don’t lie to yourself, be honest.
Ask For Help
You don’t have to go on this journey alone. There are many people out there who would be glad to lend a helping hand. You can find these people on StackOverflow, various Slack groups, and by directly reach out to ask for help.
The resources listed below have proved invaluable to me over many years of iOS development. This is by no means a definitive list but should definitely help get you started.
Homebrew is a package manager for installing developer tools on OS X. You’re going to need this at some point so why not install it now?
Quick Look Plugins
Quick Look is that window you see when you tap the spacebar when you have an item selected in Finder and other places. Sindre Sorhus has graciously put together a list of the most popular Quick Look plugins for developers. I recommend getting them all.
From Charles Proxy:
Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet. This includes requests, responses and the HTTP headers (which contain the cookies and caching information).
Charles Proxy has saved me an obscene amount of hours when working with APIs. Being able to see all HTTP traffic will help you validate or invalidate your assumptions when dealing with APIs. Download this tool now.
Dash is an API Documentation Browser and Code Snippet Manager. Dash stores snippets of code and instantly searches offline documentation sets for 150+ APIs. Dash is much better than Xcode documentation viewer. The factor that it supports other languages API documentation is fantastic too.
Sublime Text 3 is a sophisticated text editor for code, markup and prose. You’ll love the slick user interface, extraordinary features and amazing performance. Sublime Text is useful for editing files that you wouldn’t necessarily want to edit with Xcode or a simpler text editor.
Fastlane lets you define and run your deployment pipelines for different environments. It helps you unify your app’s release process and automate the whole process. Fastlane is a suite of tools that perform different tasks. You can use any tool by itself if you desire. Once you’re getting ready to submit an app to the App Store definitely give Fastlane a look.
Blogs, Websites, Newsletters
WWDC Videos are an invaluable resource for both beginners and experts alike. I highly recommend reviewing the latest WWDC videos. Some of my favorites from WWDC are Protocol Oriented Programming In Swift and Advanced NSOperations.
Little Bites Of Cocoa (Blog)
Little bites of cocoa is a daily publication aimed at providing small, bite-sized (get it?) tips and tricks for iOS and Mac development. The goal of each of these bites is to give the reader a brief overview or explanation of a particular concept, technique, or tool. Bites are not intended to replace full API documentation, but rather to compliment it.
NSHipster is a journal of the overlooked bits in Objective-C, Swift, and Cocoa. Usually updated weekly but it’s been a bit slow the past few months. The content is incredibly well written and easy to read.
NSScreencast ($9/month) is a fantastic resource for bite-sized iOS development tutorials. Production quality is top-notch and episodes average between just 10-15 minutes. NSScreencast is great for both the novice and expert iOS developer alike. Highly recommended.
RayWenderlich.com features a wealth of tutorials on just about any iOS topic you can imagine. This is a great
iOS Dev Weekly (Newsletter)
iOS Dev Weekly is a weekly newsletter with a hand picked round up of the best iOS development links every week. Curated by Dave Verwer and published every Friday. Free.
StackOverflow is a community driven programmer Q&A site. Chances are you’ve already visited StackOverflow to answer a development question. You will find answers to just about any iOS question imaginable. Keep in mind that the correctly marked answer is not always the best answer. Always look at the other answers, especially those that are higher voted than the “correct” answer.
Twitter is an invaluable resource for learning about iOS development and staying abreast of the latest news. I probably source ~80% of my news and interesting article from Twitter. Here’s a few people to follow who I think are pretty awesome:
@nshipster - Updates posted for new NSHipster articles and other cool bits of Swift and Cocoa.
@natashatherobot - Natasha is a brilliant iOS developer. She frequently tweets and blogs about Swift related topics whose content is easily accessible to developers of all skill levels.
@steipete - Peter Steinberger is the creator of PSPDFKit, the most advanced PDF framework for iOS & Android. Peter talks about a wide variety of topics and is incredibly knowledgable about iOS.
@mattt - Mattt Thompson is legend. He is one of the most prolific iOS open source contributers in history and the original creater of AFNetworking, and later AlamoFire.
@jamesthomson - James Thomson is a long-time indie iOS/Mac developer and tweets about a variety of interesting Apple topics.
@andy_matuschak - Andy is a life-long learner and worked on UIKit from iOS 4.1 through iOS 8. Andy currently leads mobile engineering at Khan Academy.
@soffes - Sam Soffes is a prominent iOS developer and all-around cool guy who has contributed many incredibly usefu open source libraries over the years.
@nicklockwood - Prolific open source contributor. Currently works at Facebook on React Native.
@mikeash - Mike is a deep thinker and author of Friday Q&A, an invaluable resource for those looking to go deep into Swift and Objective-C runtime topics, among other things.
@KrauseFx - Felix Krause is the creater of Fastlane and tweets on a variety of interesting topics.
My vote for Twitter clients would be for TweetBot or Twitterific. I recommend staying far away from the official Twitter client unless you want to be a guinea pig in Twitter’s A/B tests and be subjected to ads.
There are so many awesome open source projects out there. Reading through well architected projects will make you a better developer. Here are some of my favorites:
Alamofire - Arguably the most popular iOS open source in recent member, Alamofire is an extremely well-written, elegant HTTP networking library.
Static - Static makes creating simple static table views a breeze. Highly recommended for rapid prototyping.
DZNEmptyDataSet - A drop-in UITableView/UICollectionView superclass category for showing empty datasets whenever the view has no content to display. You need this.
Realm - Realm is mobile database solution that aims for simplicity and power.
Awesome Swift - A curated list of awesome Swift resources.
Open Source Apps - A curated list of open source iOS apps.
Here are some areas you will want to explore as you progress further on your iOS development journey:
- Beta testing & distribution
- Application submission
- Composition vs. inheritance
- Open source software licensing, see tldrlegal.com.