How I learned Swift and what I know about Swift - Part 1

Following on from my 'Brief History' post, this other retrospective is to help me make sense of what I know about Swift so far and to summarise the journey I've been on with it. Subsequent posts in this blog will involve up-to-date thoughts and reflections on my current learning of Swift.


Here is how I went about learning Swift:


In April 2015, I started off learning Swift with several Udemy courses, including one by Rob Percival, which was very popular and highly-rated. At first, I had the naive assumption that it would all be very straightforward and easy to pick up. It wasn't! Rob's course was great if you were confident with the language, but the halfway point I was lost. The tasks seemed to be impossible to figure out without some insider knowledge. Anyway, I supplemented that course with several others on Udemy, which helped me to learn what the basics were.

From there, I found a useful site: 'WeHeartSwift', which were useful in carrying out challenges, just to get used to the syntax and develop my problem-solving skills. I was pleased to find that I could think creatively for simple tasks - a fundamental requirement for any coder! So, after initially feeling a bit deflated from that first Udemy course, I started to gain confidence. From there, I embarked on a couple more Udemy course, a Tuts one and eventually found Treehouse. The latter was perfect for what I needed at that point - going over all of the key elements of Swift with more challenges that seemed relevant for my level. Anyway, at this point, my time dedicated to Swift petered out, then stopped abruptly as I made the move to Dubai, in August of 2015.

In July of the following year, I picked up Swift for the first time in nearly a year, finding that some of what I learned had been retained but a lot had been forgotten. Using the Swifty app was a great way of reminding myself of the basic syntax for the different aspects of what I had learned. Again, going back to Dubai the next month until Christmas time of 2016 meant that I slipped back in my development, so I resubscribed to Treehouse for a week or so, spending an hour or so a day in going over the fundamentals.

This pattern of learning-forgetting-relearning continued into the following Summer of 2017, and takes us to the present of December. Though this time, I've spent several weeks on Swifty, Treehouse and another app called SoloLearn to go over the basics to the point that I'm relatively confident. I've just purchased an Ebook, 'Learn to Code in Swift 4' by Kevin McNeish, which so far seems to be the best combination of Swift essentials with practical application that I've found so far.

Now I've outlined how I went about learning Swift, now it's time to ascertain what I know.


What I'm going to explain here will undoubtedly be incorrect in places; it is simply to show what my understanding of Swift is, at this point...


Variables and Constants; Numbers and Strings

Like any language, Swift is made up of various elements. The syntax is important - how certain objects need to be declared and written and there are certain terms to know how and when to use.

Variables (var) and constants (let) allow you to assign values to a certain type. Types can be numbers (Int, Float or Double), words/letters (strings/characters) and true/false (Boolean). You can declare these explicitly but Swift can 'infer' this, which is clever!

var number = 4

That is a variable whereas: let number2 = 5 is a constant.

Variables are mutable - they can change/mutate whereas constants can't. I could not redeclare the value of number2, but I could for number. Like with any calculator, I can add, subtract, multiply, divide, find the remainder (% symbol). To make it clearer, a new constant/variable can be created which uses others.

E.g. var number 3 = number * number2

*number 3 could also be a constant, as long as I'm not planning to change it. It is considered better to use constants.

So there is a lot you can do with numbers. Using text ('String' type) does not involve calculations, but there's still plenty to play around with.

let firstName = "Josh"

let secondName = "Swift"

*camelCase is used for declaring var/lets.

print(firstName + " " + secondName)

What is printed will be "Josh Swift". 'String concatenation' is combining strings this way with the + operator.

I coud also use 'String interpolation', which means putting a var/let into a new string.

let nameMessage = "My name is \(firstName) \(secondName)"

The same can be done with numbers. Going back to numbers, you can't mix up types. 'Doubles' are numbers that can be decimals (so are Floats, but I never use these).

So if var number = 3 and var newNumber = 4.2, I couldn't calculate with these. I would either make number 3.0 (Double type) or convert number to a Double.

Types in general can NOT be mixed up as it confuses Swift and creates an error.


In the next post, I will explain what I know about other types and elements of Swift

Comments

Popular posts from this blog

*Xcode Project Entry 2* F1 Quiz - part 1

Angela Yu Course Part 10 (up to lesson 112)

Angela Yu Xcode 12 Course - Part 7 (lectures 74 to 79)