Welcome to Swift Basics
You need to know the building blocks to get started with the Apple Swift language today. These core Swift iOS fundamentals will enable you to start making iOS applications. Even if you are new to programming these articles will help you get started.
I recommend working down the list, although the articles are designed for you to jump in anywhere to get the answers you need right now based on your experience and the solution you are looking for.
Variables are the very DNA of our applications, without them we there is not much we can do. Variables are defined, used and changed on the fly unless they are constants. In Swift like other languages there are some rules to follow, here are the common ones you need to know to get started…
Functions (in a class you will see them called Methods) are blocks of code that perform a task and either return something back or adjust something elsewhere in your program. Functions can be called with parameters that are used in the functions code.
Classes Part 1
Classes in Swift are something you will be using a lot if you want to really get to grips with creating applications. OOP (Object Oriented Programming) is a vital iOS core skill. This first part covers the basics of creating and using classes.
Classes Part 2
A few concepts for taking your understanding of Classes to the next level in Swift. I am certain many if not all of these are techniques you will use over and over. Topics include subclassing, overriding properties in subclasses and observers.
You maybe familiar with Closures from other languages, simply put they are blocks of code assigned to a variable. They can take arguments just like any other function/method and can be useful for reducing code repetition.
In Swift an Optional Type is considered a safe way to use variables. An Optional can represent a value that has been set or more importantly the lack of a set value as they default to nil when no value is present.
At the heart of a dictionary is a very simple concept, each item in the dictionary is a pair, however unlike an array the can be any kind of object, BUT all the keys MUST be the same kind of object, this also applies to the values. Keys and values do not have to be the same type though which can be handy.
Generics give us the type safety of Swift with strong typing but also allows us to deal with those situations where we do not always know what the type of something is going to be.
To quote the official documentation
"An enumeration defines a common type for a group of related values and enables you to work with those values in a type-safe way within your code."
we can use the Nil Coalescing operator along with a ternary conditional and unwrapping to check a value then set a variable based on those results without having to use an if else block.
A basic introduction on how to use the guard statement in Swift. I’ll explain why it makes code more readable and can save resources by leaving code execution early.