Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Swift Second Edition - Second Edition

You're reading from  Learning Swift Second Edition - Second Edition

Product type Book
Published in Mar 2016
Publisher
ISBN-13 9781785887512
Pages 308 pages
Edition 2nd Edition
Languages
Author (1):
Andrew J Wagner Andrew J Wagner
Profile icon Andrew J Wagner

Table of Contents (19) Chapters

Learning Swift Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Introducing Swift 2. Building Blocks – Variables, Collections, and Flow Control 3. One Piece at a Time – Types, Scopes, and Projects 4. To Be or Not To Be – Optionals 5. A Modern Paradigm – Closures and Functional Programming 6. Make Swift Work For You – Protocols and Generics 7. Everything Is Connected – Memory Management 8. Paths Less Traveled – Error Handling 9. Writing Code the Swift Way – Design Patterns and Techniques 10. Harnessing the Past – Understanding and Translating Objective-C 11. A Whole New World – Developing an App 12. What's Next? – Resources, Advice, and the Next Steps Index

Printing to the console


It is very useful to write output to a log so that you can trace the behavior of code. As a codebase grows in complexity, it gets hard to follow the order in which things happen and exactly what the data looks like as it flows through the code. Playgrounds help a lot with this but it is not always enough.

In Swift, this process is called printing to the console. To do this, you use something called print. It is used by writing print followed by text surrounded by parentheses. For example, to print Hello World! to the console, the code would look like this:

print("Hello World!")

If you put that code in a playground, you would see Hello World! written in the results pane. However, this is not truly the console. To view the console, you can go to View | Debug Area | Show Debug Area. A new view will appear at the bottom of the window and it will contain all text the code has printed to the console:

Not only can you print static text to the console, you can also print out...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}