Pretty Swifty

by Adam Gask

Exploring Swift, iOS and my battles with Xcode!

Read this first

Swift 101 - Optionals?

Coming soon!

Continue reading →

Swift 101 - nil

This is a super quick blog to go over the Swift keyword - nil.

nil is described in the Apple docs as:

meaning “the absence of a valid object.”

Not the easiest thing to understand if you’re starting out, right?

If you’re new to programming nil simply means that a variable (sometimes called an object) is empty and has no value assigned.

If you have a background in programming nil can be thought of best as a like-for-like replacement for null.

The Apple docs go on to say:

nil cannot be used with nonoptional constants and variables. If a constant or variable in your code needs to work with the absence of a value under certain conditions, always declare it as an optional value of the appropriate type

Again, not particularly easy to digest. But here Apple are saying that a variable can only be assigned nil if you as the programmer have said that’s OK. You do that by making a variable

Continue reading →

Swift 101 - let vs var

Welcome, to the first blog in my Swift 101 series!

Today I’ll be explaining the difference between let and var, two fundamental keywords in the Swift programming language. If you’re just getting started with Swift this is a great place to start learning as you’ll be using these two a lot!

Both let and var are used when defining variables. You can think of variables as bags of information which can hold a number, true or false, even some text, like "Hello, World!"

let is used for defining constants - variables which do not change their value, for example, the number of months in a year:

let numberOfMonths = 12

var is used for defining mutable variables - variables which do change their value, for example, the temperature of a room:

var roomTemperature = 21.5

Let’s take a look an example:

 Your favourite coffee shop

Imagine we run a coffee shop where we have a limited number of

Continue reading →