---
title: "#175: More Swift Tricks 🎩"
url: https://littlebitesofcocoa.com/175-more-swift-tricks
author: Jake Marsh
date: 2016-01-22
published: 2016-01-22
topics: ["Swift","Techniques"]
description: "Today we'll continue our look at interesting Swift features. Let's begin. This is great when we've got multiple optionals to unwrap."
---

# #175: More Swift Tricks 🎩

By Jake Marsh, January 22, 2016. HTML: https://littlebitesofcocoa.com/175-more-swift-tricks

Today we'll continue our look at interesting _Swift_ features. Let's begin.

## Multiple/Chained Optional Unwrapping

This is great when we've got multiple **optionals** to **unwrap**. We can even use **unwrapped references** from earlier in the **statement** in later parts of the **statement**. Neat!

``` swift
if let URL = NSURL(string: someURL),
   let data = NSData(contentsOfURL: URL),
   let ship = Spaceship(data: data) {
    // use 'ship'
}
```

## Multiple Initialization

We can **initialize multiple references** in one **statement** (and one line). This works for when using both `let` and `var`:

``` swift
let ship1 = "Tantive IV", ship2 = "Ghost", ship3 = "Outrider"
```

## Slicker Array Inits

We can simplify **Array** (and **Dictionary**) `init` **statements** like this:

``` swift
let spaceships: [Spaceship] = []
```

To this:

``` swift
let spaceships = [Spaceship]()
```

## Semicolons: Gone but not forgotten!

Removing the need for trailing **semicolons** was one of _Swift's_ most welcome features. However, they <i>actually are</i> present in _Swift_, and can serve a useful purpose. They'll let us write multiple **statements** on one line. This works great (for example) in `guard` **statements**:

``` swift
guard let error == nil else { fail(error!); return }
```
