My journey to become an iOS developer week 1

sWimmie
3 min readFeb 10, 2021

As of every journey into programming the first thing you learn is to get Hello World onto the screen. But the most important thing to learn is actually the syntax of the new language you are trying to learn.

So in the first week we started off with the concepts constants, variables and datatypes.

Constants and variables

Constants and variables associate a name (like age or name) with a value of a particular type (like the number 41or the string “Wim”). You can then use the name to refer to that value many times in your program. Once it’s set, the value of a constant is immutable, which means that it cannot be changed. In contrast, the value of a variable is mutable, which means that it can be changed at any time.

By defining a constant or variable, you’re asking the compiler to allocate storage for the value in memory on the device that will run the program. You’re also asking it to associate the constant or variable name with the assigned value so you can access the value later.

Types

Swift comes with many predefined types that make it easier to write clean code. Whether your program needs to include numbers, strings, or Boolean (true/false) values, you can use types to represent a specific kind of information. Some of the predefined types are Integer (Int) what stands for whole numbers. Double (Double) what is a type fore decimal numbers. Boolean (Bool) what represents a true or false value. String (String) what is just text.

Swift also supports collection types, which group instances into a single variable. One collection type is called an Array, which stores an ordered list of objects. Another collection type is called a Dictionary, which has keys that help you look up specific values. You can use collections to store multiple objects in a single constant or variable.

Next to the standard types you can declare your own types inside a Class or Struct. It needs to be said that Apple prefers Structs over Classes. Because a Struct is less memory consuming.

Swift is considered a type-safe language. Type-safe languages encourage or require you to be clear about the types of values your code can work with. For example, if part of your code expects an Int, you can’t pass it a Double or a String.
When compiling your code, Swift performs type checks on all of your constants and variables, and flags any mismatched types as errors. If you mismatch types, you won’t be able to run your program.

You do not need to explicitly declare a type on a variable or constant this will be done once you set a value to that variable/ constant. This is called type-inference. So if you declare the variable var firstName; and later set firstName to 41 this means that the type would become an Int. And not String as you might expect from firstName. Therefore you can set the datatype on forehand to a variable like var firstName: String then you can only pass in Strings into the variable firstName.

This is the things we learned in the first week onto my journey to become a iOS Developer. Next week we will look into some basic programming concepts in Swift.

--

--

sWimmie

On a journey from Urban Designer to Software - / Front end developer to iOS developer