Tips for Swift syntax

Source: Internet
Author: User

What is Swift?

Swift is a scripting language published by WWDC.

Benefits of using Swift: OC ARC The biggest difficult memory management

And Swift doesn't have to worry about memory. Simple, functional

Very powerful, simple syntax and OC language can call each other.

But there are weaknesses, not high security: H. m

two of Swift do not need: 1. No need to write the main function

2. There is no need to add a semicolon in the back, of course, plus yes (the same line has two lines of code, the middle must be added;)

Syntax: 1.let modifiers are constants, constants are not allowed to change variables such as let constant 1 = 2.var defined

A swift variable or a naming convention for constants

1. Cannot have mathematical symbols (e.g. + *)

2. Cannot contain arrows

3. Cannot have illegal invalid non-encoded characters.

4. Cannot have a keyword (let, var)

5, cannot contain horizontal lines, indicator (my--name)

6, cannot start with a number

7. Cannot have only one slide line alone. (var _)

Defining variables : 1. Implicit variables

var myVar1 = "Hello"//myvar1 he is a variable of type string

var num = num system defaults to a variable of type int

var num1 = 23.0 NUM1 system defaults to a double type of variable

2. Explicit variables

var myvar1:string = "Hello"

var num:double = 23.0

Data Conversion : The following:

Let number 1:int = 30

Let number 2:double = 23.5

Let number 3:double = number 1 + number 2

If this is defined, the number 3 is an error, because the number 1 is the int type.

The number 2 is Double. The Let number 3:double = number 1 + number 2 must be converted into

Let number 3:double = Double (number 1) + Number 2

And that's the right thing to do.

Let number 4 = 22+3.11

You can use the Typealias keyword to define the alias of the type, similar to the typedef of the C language

Typealias MyInt = Int

Let Sum:myint = 23

Tips for Swift syntax

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.