Are you learning iOS development? Looking for Swift best practices? This is the right place to start your journey as a mobile application developer.
Learning a programming language is hard. Even after more than a decade of software developer experience I feel like that I'm only scratching the surface. I don't know much about low level assembly code, I don't know how to create 3D games using shaders and many more. Still we all learn something new every single day. It's a life-long journey and the path is full with obstacles, but if you keep going forward you'll find that there's gold at the end of the road. I still love to create new stuff from literally nothing but plain code. 😍
Everyone can code
In the beginning it'll feel like that you have to learn a million things, but you shouldn't be afraid because time is your friend. Day-by-day you'll learn something new that'll help you moving forward to achieve your next goal. I believe that the most important thing here is to have fun. If you feel frustrated because you can't unserstand something just ask for help or take a break. The Swift community a group of amazing people, everybody is really helpful, so if you choose this programming language to bring your ideas to life you'll meet some great people.
Now let me show you what you'll need to start your career as a Swift application developer. 👨💻
The first thing you'll need to start your Apple developer career is a Mac. Unfortunately Mac's are quite expensive machines nowadays, also the current series of MacBooks (both Air's and Pro's) have the completely broken butterfly keyboard mechanism. Hopefully this will change real soon.
I'd say that you should go with pre-butterfly models, you can look for the secondary market if you want to have a cheap deal. Otherwise you can go with a Mac mini, but if you buy one you should think about the extra expenses such as the monitor, keyboard & mouse.
If you have unlimited money, you should go with some high-end device like the new MacBook Pro 16", iMac Pro or simply buy a Mac Pro. Nevertheless you should always choose a machine with an SSD. It's kind of a shame that in 2020 a base iMac comes with a ridiculously slow HDD.
Another option is to build a hackintosh, but IMHO that's the worst that you can do. You won't get the same experience, plus you will struggle a lot fighting the system.
Quick note: you might heard rumors that you're going to be just fine with an iPad & Swift playgrounds. Honestly that's just not the case. You can play around and learn the Swift programming language even with a linux machine, but if you want to make your own iOS / iPadOS / macOS / watchOS apps, you'll need a Mac for sure.
So you've got a decent Mac. Let's see what kind of softwares will you need if you want to start developing iOS apps. You might heard that Apple's operating system is macOS. First of all, if you never used a mac before, you should get familiar with the system itself. When I bought my very first MacBook Pro, it took me about a week to get used to all the apps, system shortcuts and everything else.
If you don't want to figure yout everything for yourself, you came to the right place. Let me walk you through of every single app, tool that I'm using to my work as a professional mobile / backend developer.
The most important thing that you should get used to is the Terminal (console) application. If you never heard about terminals before you should simply look for a beginner's guide tutorial, but I highly recommend to learn at least the really basic commands.
The very first thing that you should install on your new Mac is Homebrew. If you have used linux before, might find this tool familiar (it's working on linux too). According to Max Howell (the creator):
The Missing Package Manager for macOS (or Linux)
You can also install regular applications with brew, by using the cask subcommand. e.g:
brew cask install firefox
I prefer to create a list of tools that I'm always using, so when I reinstall my machine I simply copy & paste those commands into terminal and I'm more or less ready with the restoration process. This is extremely convenient if you have to reinstall macOS from scratch.
You might noticed that I've got a thing for Terminal. If you don't like the interface of the App Store, you can install MAS, a little helper tool. With the help of it you can install everything available in the store by using Terminal commands.
The readme on GitHub is really good, you should read it carefully. Anyway you don't necessary need the mas-cli to do iOS development, but since it's really convenient, I'd recommend to check it out.
The number one tool that you'll definitely need is Xcode. There is an alternative IDE tool called AppCode, but it's always lagging behind and the vast majority of the community prefers Xcode. 🔨
A new Xcode version is released every single year with brand new features and functionalities. I'd recommend to go with the most recent one (also you should always upgrade your existing projects to support the latest version). You can get Xcode from the App Store, it's completely free.
It'll take a lot of time to install Xcode on your machine, but don't worry after a few hours it'll be ready to help you writing your very first iOS application. So be patient. :)
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Every single developer should use a properversion control system (aka. Git). Git is the de facto standard tool for version control and you can learn the basics in just about 15 minutes. Of course mastering it will take much longer, but it's totally worth to start playing around with it.
GitHub is a web-based hosting service for version control using git.
To be honest, GitHub it's not just a repository hosting service anymore, it's a complete platform with tools for issue management, project planning, continuous integration support and many more.
GitHub offers you a free tier both for public and private Git repositories for individuals. In 2019 it was acquired by Microsoft (everyone was afraid of this change, since MS has some history about ruining good services), but until for now they introduced lots of amazing new features. Go and get your free account now!
I believe that Swift has evolved to a stable & mature language during the past 5 years. If you think about it, it's the only good option to write future proof iOS apps. You should clearly forget Objective-C, since Apple already made his choice. Eventually Swift will be the only programming language that Apple supports, there are already some frameworks that are Swift "only". Just take a look at on SwiftUI. I mean you can't write SwiftUI views in Objective-C, although the framework is 100% compatible with Objective-C based projects.
At some point in time you don't want to write everything by yourself, because you'd like to make progress fast. This is where external packages are coming into the picture. Take my advice:
Never connect 3rd-party libraries by hand
The Swift Package Manager is natively integrated into Xcode. In the past CocoaPods was the ultimate dependency manager (some people preferred Carthage) for iOS projects, but nowadays it's way better to use SPM. If you need to integrate external libraries SwiftPM is the right choice in 2020. If you don't know how it works, you should read my comprehensive tutorial about how to use the Swift Package Manager.
I also made a quite popular article about the best / most popular iOS libraries written in Swift last year. It was featured on Sean Allen's (Swift News) YouTube channel. Unfortunately he stopped that show, but he is still making some really good videos, so you should definitely check his channel if you have some time.
Anyway, if you don't know where to start and what to integrate into your Swift project you should go and read my blog post, since it's still up-to-date. Fortunately these things are not changing that often.
Picking the right architecture for your upcoming iOS project is one of the hardest things. The other one is building up your user interface, but let's keep that topic for another day. You should never be afraid of architectures. Even if you choose MVC, MVP, MVVM or VIPER you can have a really well-written application strucutre. This is really important, because you don't want to make your future self angry with some 2000+ lines sphagetti coded view controller with some nasty side effects.
So how you should pick an architecture? Since there a lots of them, you can even come up with a random one. Well, this is a real debate amongst iOS developers. My favorite one is VIPER, though I get a lot of criticism because of this. Honestly I really don't give a damn about this, because it works for me (and my teams). Whether you go with plain old MVC it really doesn't matters until it can solve your issue.
If you are a completely beginner please don't start with VIPER, unless you can have someone by your side who can answer all your questions. My advice here is just to simply sit down and think through what do you want to achieve and make a basic plan. Of course it helps a lot if you are familiar with the patterns, but in the end of the day, you'll realize that all of them are made by humans and none of them is perfect. 🤔
I made some really basic conventions for Xcode that you should check if you don't know how to organize your projects. If you are not familiar with Xcode formats, targets, schemes, you should search the internet for such a tutorial, there are some well-explained examples about the entire thing.
You know just like in real life, you don't throw all your clothes into the shelf, right?. Being well organized is the only way to create a good project. Fortunately Apple realized this as well, and now groups are represented as physical folders on your hard drive by default.
There is a reason that warnings exists, but you should never leave any of them in your production code. If you want to be more radical, there is a build flag in Xcode to treat warnings as errors. TURN IT ON! Kill all warnings! Haha, don't do that, but you should always try to fix all your warnings.
You know that awkward situation, when you open a source file, and you start scrolling, scrolling and you have to do even more scrolling. Yep, usually that's a massive view controller problem and you already know that you are lost forever. If you get to this point, you can try to refactor your code by introducing a new object that can take over some of the functionality from your controller class.
If there is a best practice, use that. You should always look up the problem before you start coding. You should also think through the problem carefully before you start coding. Remember: you are not alone with your coding issues, I can almost guarantee that someone already had the exact same issue that you are working on. StackOverflow is the right place to look for solutions. Use the power of the community, don't be afraid to ask questions on the internet, or from your co-workers, but don't expect that others will solve your problem, that's your job.
In this section I'm going to give you some real quick advices about how to write proper Swift code. I know I can't have everything in this list, but in my opinion these are some really important ones.
Look, if you know what is the "Great" Pyramid of Doom, you'll know what I'm talking about. You're going to write async code eventually, most of the API's have async methods. Even a simple networking task is asynchrounous. It's a smart move to learn how to write proper async code from the beginning.
There are a few approaches that you can choose from.
Of course you can go old-school by using completion blocks. That's a good way of learning the concept and you can practice a lot, but there are way better options to write good async code in 2020.
Promises are high level abstractions over async tasks, they'll make your life SO MUCH BETTER. You the real power comes from the fact that you can chain & transform them using functional methods. Promises are amazing, but they don't really have built-in support for cancellation.
You can go with NSOperation tasks as well, but if you'd like to have some syntax sugar I'd recommend Promises. My problem is that if you have to pass data between operations you'll have to create a new operation to do it, but in exchange of this little inconvenience they can run on queues, they can have priorities and dependencies.
I believe that the brand new Combine framework is the best way to deal with async code in 2020.
They are the root of all evil. Honestly, avoid singletons as much as you can. If you want to deal with mixed-up states & untestable code, just go with them, but your life will be better if you take my advice. If you don't know how to avoid the singleton pattern please do some research. There are lots of great articles on the net about this topic.
One exception: you can use a singleton if you are especially looking for shared states, like cache mechanisms or a local storage object like
UserDefaults. Otherwise don't use a singleton.
If you need a helper class, you are doing things wrong! Every single object has it's own place in your codebase, helpers are useless & not good for anything. Rethink, redefine, refactor if you need, but avoid helper classes at all cost. Learn about Swift design patterns or draw a chart about your models, but trust me there is no place for helpers in your code.
Using globals is a really bad practice. Eventually some part of your code will override the global property and things are going to be pretty messed up. You can avoid side effects by simply eliminating those global variables. Also going functional is a neat way to improve your code.
You should always write tests, I'm not saying that you should go with TDD, but unit tests are good practice. They'll help you to think through the possible mistakes and they validate your codebase. Also UI tests are good for validating the user interface, plus you can save countless hours if you don't have to run manual tests.
I know it's quite a list. Don't be afraid, you don't have to learn everything at once. Beginning your iOS career is not just all about learning new stuff, but you should have fun on the road. 😊
Be patient & consistent. Always dedicate a fixed amount of time per day to code. It really doesn't matters if it's just half an hour, if you do it every day you'll form a habit and the numbers will sum up as well. In this busy world, it's really hard to find some time to really focus on something, but if you really want to learn how to write Swift code, this is the most important step that you need to take.
Being motivated is easy if you have a "dream". Do you want to build an app? Do you want to learn how to write something in Swift? Do you want to have a better job? Do you want to make a game for your kids? All of these things can be great motivators. The problem starts when you constantly hit the obstacles.
Don't be afraid! Being a programmer means that sometimes you just try & fail. If you want to be a real good developer you should learn from those mistakes and do better on the second time. Of course you'll learn a lot from other people as well, but sometimes you have to solve your own problems.
Don't try to aim for one really big goal. Celebrate the little success stories and achievements. You should also be proud of what you've done "today". It's easy to forget to remember these little things, but making an app or learning a new programming language is a long-term project. If you don't have your small moments that you can celebrate eventually you will lose motivation and interest for the "project".
I think these three things are the most important non-technical skills if you want to learn Swift. Have your very own dedicated time to code every single day. Gain motivation from your dream (follow the big picture), but also celebrate every little success story that you achieved. Go step-by-step and you'll find that there is nothing that you can't learn. Anyway, technical skills are just secondary... 🤷♂️
It's really good to see that there are still plenty of dedicated people who are keeping up writing about the good and bad parts of iOS / Swift development. Here are the best resources that you should know in 2020.
In the past year I've interviewed lots of iOS developer candidates. Absolute beginners are always asking me the same question again and again: where should I go next, what should I learn next?
There is no definite answer, but this year I'm trying help you a lot. This is the very first year when I'll dedicate more time on my blog than on anything else. No more new client projects, no more excuses.
So here is my advice: follow me on twitter, subscribe to my newsletter and check my site every single week, because some really amazing stuff is coming soon... 😉
You should check out my favorite continuous integration & delivery service, because those guys at Bitrise are creating a truly amazing piece of software. It's time to automate your development workflow: save your time, try Bitrise!Sign up for FREE Thank you for your support
Subscribe to my monthly newsletter. On the first Monday of every month, you'll get an update about the latest Swift news including my articles and everything what happend in the Swift community as well.