The document

Before you get started, check out apple’s official introduction to Swift (Chinese version).

Swift is introduced

To start learning Swift, you can see the official documents of Swift. This document is Swift Language Guide, which covers the various common features in Swift and is worth reading. Contents include data types, functions, closures, enumerations, structs and classes, properties, methods, subscripts, inheritance, constructors, error handling, concurrent programming, extensions, protocols, generics, and more.

Swift Language Guide

video

Apple opened the Swift code in 2014, and Swift has changed every year since. WWDC has lots of Swift videos to keep you up to date on what’s going on in the Swift language. As of now (2021.6), Swift language has been updated to version 5.5.

Swift (WWDC)

WWDC, however, is full of videos explaining new features of Swift, making it less suitable for beginners. For beginners who want to quickly learn about Swift, you can use Playgrounds. There’s a video you can watch

Swift Playgrounds


The development environment

Here are two ways to learn Swift. You can choose one you like.

Playground

You can use Xcode on macOS. Search for Xcode installation in the App Store. The installation process is slow and takes some time. Then use Playground to learn, the development environment is very simple, no need to do additional configuration, directly create a Playground file can start to write Swift code, click the left run button to run and view the execution results of the program.

Click on file-new-playground to pop up a dialog box

Select the default Blank.

Give your app a name and start programming

Write down the code

import UIKit
​
var greeting = "Hello, playground"
print(greeting)
Copy the code

Click the run button on the left side of the code, and both the console and the right area of the Playground output the values of the variables. In Playground, you can define functions, define classes, etc., and try Swift related syntax.


New construction

On MacOS, in addition to Playground, you can create a new Swift project to learn about Swift.

File-new-project, click on it and the popup box pops up

Select Command Line Tool under macOS. A dialog box is displayed

Once the project is created, you can write the Swift code. The project main.swift is the main entry point for the program, and you can write code directly to the file

import Foundation print("Hello, World!" )Copy the code

When it runs, the console prints Hello, World!


To get started, look at the basics, such as variable types, flow control statements, function definitions, class definitions, enumerations, and so on. Much of the syntax of object-oriented programming languages is similar, and if you have a foundation in other programming languages such as Java,Python, etc., Swift is quick to get started. At present, Swift is mainly used for apple-related development. Learning Swift is the basis of iOS development and Mac development.

For more information

included