Book Image

Swift Essentials - Second Edition

By : Alex Blewitt
Book Image

Swift Essentials - Second Edition

By: Alex Blewitt

Overview of this book

Swift was considered one of the biggest innovations last year, and certainly with Swift 2 announced at WWDC in 2015, this segment of the developer space will continue to be hot and dominating. This is a fast-paced guide to provide an overview of Swift programming and then walks you through in detail how to write iOS applications. Progress through chapters on custom views, networking, parsing and build a complete application as a Git repository, all by using Swift as the core language
Table of Contents (17 chapters)
Swift Essentials Second Edition
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
Index

Displaying objects with Quick Look


The playground timeline can display objects as well as numbers and simple strings. It is possible to load and view images in a playground using classes, such as UIImage (or NSImage on OS X). These are known as Quick Look supported objects, and by default include:

  • String (attributed and unattributed)

  • Views

  • Class and struct types (members are shown)

  • Colors

Tip

It is possible to build support for custom-based types into Swift by implementing a debugQuickLookObject method that returns a graphical view of the data.

Showing colored labels

To show a colored label, a color needs to be obtained first. When building against iOS, this will be UIColor; but when building against OS X, it will be NSColor. The methods and types are largely equivalent between the two, but this chapter will demonstrate using iOS types.

A color can be acquired with an initializer or using one of the predefined colors that are exposed in Swift using methods, as follows:

import UIKit // AppKit for OS...