For this chapter, we shall look at this brilliant new feature called Playground. You can simply type the code you see in this chapter in a Playground, and it will run and show the results without having to compile or run the application. However, there are a few things to note before we start:
The language supported by Playgrounds is a new language called Swift, introduced by Apple. You cannot have (as yet) a Playground with Objective-C as the code language.
The entire file is a single Playground and called so too. This means that the compiler treats it like a single source file. This can give rise to issues where, for example, if you used a variable called
temp
asstring,
and further down you used it as anint
, the compiler would throw an error complaining that the variable is being redefined.The code you can type in a Playground is specific to the platform of the Playground, that is, iOS or OS X. This affects the code in terms of the classes available for use, CocoaTouch...