I'm a black horse-----swift Basic syntax

Source: Internet
Author: User
Tags case statement

Variables and constants:

If you want to define a variable equal to 1, just write var = 1,swift will automatically make type inference.

If you want to define a constant pi equal to 3.14, just write let PI = 3.14, constants can only be assigned once.

Output statement:

You can use the printf function directly to output an arbitrary type of information:

Prinft ("Hello Swift");

String Connection:

If all two variables are strings, you can connect directly with the + sign:

" Hello " var word " Word "  = Hello + Word

If you want to connect the value of the other types of sea oil, then directly using \ () includes the connection can be made:

1 " Hello " 2  - 3 " \ (hello) \ (num) "

Cycle:

Traditional C-language loops:

 for (int i =1;i<; i++) {    //TODO}

In Swift:

1 inch 0.. <{2     //TODO3 }

Condition Judgment:

As with the C language, there is no difference.

In the swift language, the Swith...case statement can be used without the break keyword.

Function:

If you want to define a function to output a piece of information:

func SayHello () {    printf ("Hello Swift");}

Object-oriented:

Definition of the class:

1 class hello{2    func SayHello () {3         printf ("Hello Swift  "); 4     }5 }

The change example defines a class named Hello, in which there is a crown function called SayHello.

Call Function:

1 var h = Hello (); 2 H.sayhello ()

Inheritance of the class:

1 calss hi:hello{2 }

I'm a black horse-----swift Basic syntax

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.