Swift Development Learning-02 variables and constants

Source: Internet
Author: User

This tutorial is a summary of the author's self-taught ios/swift knowledge, which applies to the application of objictive C programming and the need to understand the iOS program-based iphone and ipad programmer. Be a bigger ' siege lion ', work with dignity, work happily, enjoy work.

A Grammar notice

    • The source file name extension for Swift is. Swift.

The source file name extensions for OBJECT-C are. h and. M.

    • 2 Not required

1) You do not need to write the main function

Execute the code sequentially from the top down, so the first code is automatically used as the entry for the program.

2) You do not need to add a semicolon after each statement

10
If you want, each code statement can also be added;
let radius = 10;
There is a case where the code statement must be appended with '; ' (semicolon): when there are more than one statement on the same line of code
    • Comments

1) Single-line comment

// This is a single-line comment

2) Multi-line Comment

  /* This is a multiline comment, which is a multiline  comment. */

3) Multilayer annotations can nest multiple lines of comments

/* Outer comment/* Inner comment     */ */
    • Constants and variables

1) How to declare constants and variables

Declare constants with Let

10

declaring variables with Var

 - var x=0.0 , y=0.00.0

Two first Swift programs

Example: The classic code for any development language, print out the Helloword in the console.

Import foundationprintln ("Hello, world! ")

If you are printing Helloword in the Java language, the code is as follows.

class firstclass{  publicstaticvoid  main (string[] args) {     System. out. println ("Hello, world! " );  }  }

Three PlayGround

Swift Development Learning-02 variables and constants

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.