---
title: "#200: Synthesized Initializers in Swift 🚀"
url: https://littlebitesofcocoa.com/200-synthesized-initializers-in-swift
author: Jake Marsh
published: 2016-02-26
topics: ["Swift","Techniques"]
description: "Way back in Bite #1 (zomg!) we talked about initializing View Controllers in Swift. Swift's init functions are still a source of confusion for many newcomers."
---

# #200: Synthesized Initializers in Swift 🚀

By Jake Marsh, February 26, 2016. HTML: https://littlebitesofcocoa.com/200-synthesized-initializers-in-swift

Way back in [Bite #1](https://littlebitesofcocoa.com/1) (zomg!) we talked about initializing **View Controllers** in _Swift_. _Swift's_ `init` **functions** are still a source of confusion for many newcomers. Today we'll look at a couple cases where _Swift_ <i>synthesizes</i> `inits` for us.

## Structs

_Swift_ offers free "<i>memberwise"</i> **initializers** for **Structs**. This means that if we define a **Struct**, and opt not to define any **initializers**, one will be synthesized for us, under the hood, using the **properties** we've given to the **Struct**. If we add our own though, we <i>lose the synthesized init</i>, and become responsible for defining 100% for the **Struct's** `inits`.

``` swift
struct Spaceship {
  var name: String
}

let ship = Spaceship(name: "Outrider")
```

## Default Initializers

**Classes** can synthesize a default `init` **function** for us. Only one that accepts **0 parameters**, though. We'll get this if we define a **class**, while assigning default **values** to all its **properties**:

``` swift
class Spaceship {
  var topSpeed = 1000
  var currentSpeed = 0
}
```

``` swift
let ship = Spaceship()
```

There's plenty to cover about `init`'ing things in _Swift_. We'll take a look in future **Bites**. Oh, and happy _200th_ _Bite_ !
