Swift Introductory chapter-hello World

Source: Internet
Author: User

Tip: If you use your phone and tablet to see this article, please read it in the WiFi environment, there are many pictures, it will waste a lot of traffic.

Bo Master language has been bad (if there are any typos, please comment) hope you understand, have not learned anything

The most recent 2 days have been to upgrade systems and upgrade development tools and to chew on Apple's development documentation, as well as to write Swift articles. I also learn swift while doing some small examples to play. Personal feeling of grammar refining, it is still very cool to use.

But personally feel that the development tools still have a lot of shortcomings (such as automatic hints sometimes do not appear), I hope that Apple in the release of the official version can be repaired a little better, in the back I will write down the experience of my mistakes.

Today is the official swift language, starting with the "Hello World" program.

Personal development environment:

System

OS X Yosemite 10.10

Tools

Xcode 6.0 Bate

If you do not have a developer account to download Xcode 6.0 bate, please go to Swift's introductory article-swift introduction

---------------------------Formal Development------------------

First step: Find the Xcode 6.0 BATE application, and click on the Xcode 6.0 Bate app

The second step is to click on the "Create a New Xcode Project" program.

Step three: Select "Application" under OS x, then select "Command Line Tool" and click Next.

Fourth step: Fill in the "Project name" in "Product name" and select the "Swift" language in "Language". , click Next.

Fifth Step: Select Save Location, click Create

Sixth step: Double-click the Main.swift file, the following interface appears

/*----New This Hello World this project  is for me to introduce you to one: Main.swift file  is the entry of the program Example 1:  //  main.swift Explanation: Double slash (//) is the identification of a comment. Identify program readability Examples 2:import Foundation interpretation: Import is a keyword for swift, the role of the import header file    foudation is the head file of Swift's framework. If you have a  good understanding of ojbect-c should be very clear),  if you have not learned object-c language is not related, you first understand, will be introduced in the following. Example 3:println ("Hello, world!") Explanation:p Rintln () is an output function (also called a print log) that outputs a string directly. */

Here's a look at the use of the println () function:

1: Direct Output string

  main.swift//  helloworld//import foundationprintln ("Swift")//Direct output string println ("My first Swift")//Direct output String

Note the point:

println ("SWIFT") is not followed by a colon and does not have an error.

println ("Swift") and println ("Swift");
The meaning of expression is the same.
But Apple recommends that developers use the println ("SWIFT") developer documentation to use the

Run results

2: The placeholder output placeholder for the notation \ () parentheses must put constants and variables (note that the constant in parentheses cannot be a string, only the basic types such as shaping floating-point types)

  main.swift//  helloworld//import foundationprintln ("Hello World \ (1)"),//  \ () is a placeholder  1 is a constant

Run results

Wrong wording

  main.swift//  helloworld//import foundationprintln ("Hello World")//error notation  \ () inside can only put the shape of floating-point type such as basic type, cannot put string

Today only to introduce here, the back of the article, I went back to learn from the Swift language of the knowledge to write to form a series. As a new language, personal understanding inevitably has shortcomings, welcome to give me advice. can also add my QQ 14,360,511,081 discussion, if you have any problem, you can also directly in QQ message sent to me, I saw the first time after you reply

Swift Introductory chapter-hello World

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.