My approach on learning to code in Swift
I guess it was only a matter of time before I would start learning to code, as my boyfriend is a passionate and gifted self-taught iOS programmer and we have lots of nerdy friends. Conversations about programming, tools and techniques have surrounded me for quite some time. I always have admired the freedom it gives you, if basically all you need to work is your computer. The thing is that starting without any basics can be quite tough. I am going to describe what I did to overcome these difficulties.
Since I love using my iPhone and my iPad, I wanted to create apps much more than building websites. With Swift being announced in 2014 it seemed best to start then, as it made everything so much more comprehensible than Objective-C. The issue was to find a project that would interest me enough to squeeze it in a tight schedule between a full-time job and a busy life in general. At that point nomadlist.io was all over twitter and since we both love traveling, it seemed perfect as a first project. It had a public API at the time so we were good to go.
At that time I still had no idea which piece of code to put where and why. So my boyfriend and I started together and I kept going with repetitive tasks on my own. The app showed a tableview with a picture for each travel destination. You could also tap on each one to see its details. All of it was dynamic, so whatever changes someone made to the content of the website it would be shown in the app as well.
I was very happy and proud because it looked beautiful and (even though with help) I had created it. The hard part was accepting that even small changes in the design or implementing a new piece of information was almost impossible by myself.
Unfortunately this project came to a sudden end when the API was changed to private and none of my code worked anymore.
I’ll skip a few months and to what led to the next step…
Meanwhile we had quit our jobs and decided to go on a nine-month trip to South East Asia. We moved to Chiang Mai, Thailand in October 2015.
Back in Hamburg I had managed to acquire a project with a friend of a friend who was ok with me learning on the job and taking my time. Now I am trying out if I am capable of programming and creating usable apps at all and whether I can imagine doing this full-time and successfully enough to make a living. So here is how I got started, what has helped me and what I have learned three months into the experiment.
Get used to vocabulary and terms
To get a proper understanding of the meaning of terms I took a video course on Udemy called 60 Minutes of Swift. In only one hour it covered the basics of variables, constants, if-statements, loops etc. Most important for me: it was in German. If you learn something new it helps a lot if you don’t need to worry about the vocabulary. So if English is not your mother tongue, I would highly recommend taking a basic course in your first language, since this is the basis for everything that follows. It helped me a lot to get a better understanding of the relevant terms.
Take a course and code along
To really dive in I bought another course on Udemy called iOS 9 and Swift 2: From Beginner to Paid Professional. There are loads of courses around this topic and this one worked for me. Just have a look at the reviews and promotion videos to find the course and instructor which appeals to you.
The good thing on Udemy is, they have promotions all the time so you actually never pay the full price. When I purchased the course I got a 97 % discount on the regular price.
This course covers the basics as well as advanced procedures. You go along with the instructor and, lesson by lesson, you build more and more complex apps. What I found very helpful is that you have tests and “homework” so you don’t just copy the instructions but you also have to think for yourself and put the things you just learned into new context. So there is no pretending.
Also you can go along at your own pace. If you don’t understand something just keep re-watching the lesson until you get it and of course you can skip lessons if they don’t cover your interests.
And: You can modify the example projects according to your own style and when people ask what you have done so far you can just pull out your phone and show them.
Get a project
You need to find a project that you are passionate about. It should either solve a problem or create value for you or for somebody else, something that you will stick to even when you think you will never get it to work and you still want to continue after having wasted three days with no progress whatsoever. I did not come up with this kind of idea myself but at no time was I willing to admit that I couldn’t deliver the results I had promised.
Transition what you learned
I followed my Udemy course until I had the feeling that I knew enough to start with my project. It is a photo app and it sounded like there was not much to it. I made quick progress in the beginning and so I thought I could finish it within a few days. As it turned out, it took me about six weeks.
I underestimated how much I still didn’t understand of how “computers think”. You basically need to tell them everything.
For example I thought if photos are added to a new album you could automatically scroll through them. Turns out you need to make quite some effort until it actually looks and behaves the way you would expect.
For somebody who knows programming, no matter what language, this may sound stupid, but not knowing what it takes, you make funny assumptions, I guess. Especially because using apps feels so effortless most of the time.
Keep track of your to-dos
I use Trello to keep track of what I have to do. Write down the bits and pieces you have to get done, but not like “Build App”. It helps you to focus if you don’t try to do everything at once.
If you discover a new issue while testing, create a ticket and fix it whenever you’re ready. It surprised me how many new issues come up during development. You implement one item of your to-do list and by doing so you break something that worked before. So you have to find a way around it.
Suddenly you may have to deal with cases that you didn’t even have on your mind before. For example I wanted to check how my app looked on the iPad. It crashed right away because it just didn’t know what to do when no photos had been added yet. Or another example: What is supposed to happen when you delete the last image?
You don’t need to think of all “ifs” and “whens” when you first start. Just write a ticket for anything that comes up so you will not forget to fix it and it is motivating to see how many issues you have closed already.
Use Storyboards and Autolayout
The interface builder and Autolayout are a great help because you can visually design and layout the app and also define the transition between screens.
Unfortunately not all about it is fun. Although it is called Autolayout, depending on how complex your screens are, there may still be a lot for you to do to get the results you expect.
What it does: it writes the code in the background which is needed to layout your screens. So in case of a problem, it might take some time since you have no direct influence on the code that is generated from the constraints you set. Sometimes changing a single preference can mess up everything.
More than once I deleted all constraints and re-applied them, as it is much easier than going through every single one trying to figure out which is causing the misbehaviour.
Once you have created your interface, you need to pay close attention when connecting it to your code. You can do everything perfectly fine in interface builder and code but if only one connection between the two is missing your app will not do what you expect or will just crash without you knowing why. As a beginner this can drive you nuts, especially since you don’t have the experience to know exactly where to look.
All difficulties aside I would still recommend using these tools. It’s just so helpful and motivating to have an idea what your app is going to look like. As you improve, it will feel more natural to create and change parts of your interface in code.
Find a mentor
If you are truly stuck and can’t find a way to make it work using something like Stackoverflow or other Google results, you need somebody you can ask. If you cannot rely on friends or family in that matter, user groups like CocoaHeads can be great to discuss your issues and to meet helpful and experienced people. I would not have made it all the way without this kind of direct support.
“Break” things in order to get them right
It can be helpful to implement something that you don’t want to show in your final app, in order to find out what is going on.
For example with my photos app I had the case that the photos seemed to be floating on the screen as if they had no defined place to be, which I was sure I had assigned to them. I changed the background color of the image view from white to red — of course I didn’t want a red background — but this showed that the view was much bigger than the actual image and therefor explained why the image could be moved around. Once I adjusted the constraints until all the red was covered by the image, I knew for sure it was fixed.
Use version control
I use Github.com together with the Github desktop app to keep track of the code I add and the changes I make. Try to make as many commits as possible and try to be specific in your description of your changes. As soon as you get something to work, make a commit. In case you break something and you don’t remember the changes you made, you can just go back to the state where everything worked and start over. I have made use of this opportunity a lot.
Famous last words
This is how I started and the tools and resources that helped me. I am still at the very beginning and there are so many things that I have never used, maybe not even heard of, but I hope this post gives you an idea of what it takes not only to start learning programming but also to stick with it, if you are no prodigy ;)
Create great things you would enjoy using.
Most important: Don’t be too hard on yourself. Be patient — although it can be hard — and keep going.