Swift Tutorial

Swift is an open source programming language that supports multiple programming paradigms and compiles. Apple was released at the 2014 WWDC (Apple Developers Conference) for developing iOS, OS X and watchOS applications.

Swift combines the advantages of C and Objective-C and is not limited by C compatibility.

Swift can use the same runtime environment as Object-C on Mac OS and iOS platforms.

On June 8, 2015, Apple announced at WWDC 2015 that Swift will be open source, including compilers and standard libraries.

Who is suitable for reading this tutorial?

This tutorial is for programmers who want to work on mobile (iphone) development or OS X applications, if you have a better programming foundation before.

This tutorial All examples are based on Xcode 8.2.1 (the syntax of Swift 3.0.2) to develop tests.

The first Swift program

The first Swift program of course starts with the output "Hello, World!" and the code looks like this:


/* My first Swift program*/ var myString = "Hello, World!" print(myString)

Instance Resolution

  • var myString = "Hello, World!" : Use the var keyword to define a variable myString with a value of Hello, World!

  • print : The value of the output variable

Swift introduction

We can use the import statement to introduce any Objective-C framework (or C library) into a Swift program. For example, the import cocoa statement imports the Cocoa libraries and APIs, and we can use them in Swift programs.

Cocoa itself is written in Objective-C, and Objective-C is a strict superset of C, so in Swift applications we can easily mix C code, even C++ code. .