CSC/ECE 517 Fall 2014/ch1a 13 va

From Expertiza_Wiki
Jump to navigation Jump to search

Getting Started with Playgrounds

On opening Xcode6, select "Get started with a playground".

Default is a Hello Playgrounds program.

Playgrounds with Swift introduce user friendly, clean code. Writing code in poetry-method has become simpler with swift. Unnecessary inclusion of packages and heavy syntax can be ignored. Creation of class is not required while writing code in Swift. Writing "str" in Swift would display the value of "str" on Playground directly. Semicolons are not required at the end of each line. Datatype can be stated in the code, but it is not required as Swift implicitly assigns the datatype.


If the datatype of a variable is explicitly stated, the variable cannot be assigned a value that does not belong to its datatype. Such an assignment results in an error. The error messages in Playground is shown as a ! icon. The details about the error can be viewed by clicking on this icon.

Swift introduces a new keyword "let" for declaring constants. If the value of a constant declared with "let" is changed, an error is displayed.

While iterating through a loop in Swift, the value of the iterator is shown on the console on-the-fly.