Swift QuickStart (i) First Swift program

Source: Internet
Author: User

1. Description of this series
This series is just a quick start tutorial for swift and does not have an exhaustive introduction to Swift,swift nor is it a simple programming language, so for a detailed system of learning Swift, this series is not for you, this series is just for developers to quickly develop with Swift. In addition to learning this series does not require obj-c knowledge, but if you want to develop ios,obj-c is necessary to learn, because Swift does not quickly replace the obj-c. In addition, this series is based on OS X EI Captitan 10.11.2,xcode7.2.

2. Introduction to Swift
Swift, Apple's new development language, released in 2014 at the WWDC (Apple Developer Conference), works with Objective-c on Mac OS and iOS platforms to build apps based on Apple platforms. Swift absorbs the advantages of many modern programming languages and strives to provide concise programming language and powerful features.

3. First Swift program
The first line of the swift source file executable code is the portal to Swift's program:

print("Hello World")

Swift executes statements that do not require any sign to end, and Swift takes each line of code as a statement. However, if you write more than one swift statement on a line, you should use ";" As the Terminator to the statement.

print("Hello");print("World")

The author still suggests to use ";" As the Terminator of the statement, which makes it more readable.

3. Playground Tool Introduction

Playground is a simple test environment that is designed to quickly test swift syntax functions and verify API functionality, and is not intended to be used for practical development applications. If the developer is unsure of the swift syntax, you can use playground to test the code, followed by playground to verify the functionality of a function or class.

First we start Xcode, check Playground

Then enter the name of playground in the Name text box

Playground save success will see the following editing interface, the left is the editing interface, when the developer on the left to write code, define variables and constants, you can see the right side of the variable or constant value. We'll read the code above and we'll see that "Hello world" on the right shows no problem with our code. Here is the Run button, click on the Run button, console output Hello World, the first Swift program is finished.

4. Compiling the SWIFT program with SWIFTC
The basic format of the SWIFTC command is

<生成文件> <源程序> 

We use the text Editing tool (I use notepad+) to write print ("Hello World") in it, saved on the desktop named Hello.swift
Open the terminal program, go to the Desktop directory, enter the following command:

swiftc -o hello.out hello.swift

We'll find that the desktop generated the Hello.out file, and then we execute the command

./hello.out

This command executes the Hello.out program under the current directory, and executing the program will see the output Hello World

The above compilation, run the complete process:

More videos at the Creator Academy website: www.makeru.com.cn

Embedded Learning Exchange Group: 561213221

Swift QuickStart (i) First Swift program

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.