Sebuah Tur Swift
Adalah sebuah tradisi bahwa program pertama dari sebuah bahasa pemrograman baru seharusnya menampilkan teks "Hello, world!" pada layar. Dengan Swift, ini bisa dilakukan dengan satu baris:
print("Hello, world!")
If you have written code in C or Objective-C, this syntax looks familiar to you—in Swift, this line of code is a complete program. You don’t need to import a separate library for functionality like input/output or string handling. Code written at global scope is used as the entry point for the program, so you don’t need amain()
function. You also don’t need to write semicolons at the end of every statement.
This tour gives you enough information to start writing code in Swift by showing you how to accomplish a variety of programming tasks. Don’t worry if you don’t understand something—everything introduced in this tour is explained in detail in the rest of this book.
NOTE
For the best experience, open this chapter as a playground in Xcode. Playgrounds allow you to edit the code listings and see the result immediately.
Last updated