Book Image

Swift Cookbook

By : Costa
Book Image

Swift Cookbook

By: Costa

Overview of this book

If you are an experienced Objective-C programmer and are looking for quick solutions to many different coding tasks in Swift, then this book is for you. You are expected to have development experience, though not necessarily with Swift.
Table of Contents (13 chapters)
12
Index

Watching some graphics


Knowing that a loop iterates eight times instead of 54 is fine. It gives you a good idea about the best algorithm to choose, but there are times when we need to visualize the variable's values during the loop iterations; for cases like this, Apple has created the timeline.

Getting ready

You can open your Xcode and click on Get started with playground, or if you already have your Xcode opened, you can go to File | New | Playground.

Name your project Chapter 6 Timeline and save it at your workspace folder.

How to do it...

In order to enable the app to watch some graphics, follow these steps:

  1. First, let's type a code where we print some output. In this case, we will print a triangle with stars.

    for i in 1...5 {
        for j in 1...i {
            print("*")
        }
        println()
    }
  2. Once you've typed this code, you wouldn't appreciate the triangle yet. Go to the icon that looks like two overlapped circles and click on it. The icon is shown here:

  3. Behold, the Xcode split in two parts. The...