Summary of playground, constants, variables, strings, etc. in "IOS" Swift

Source: Internet
Author: User

A few changes in code and writing (compared to OC)

1. More like the format of java,javascript or Python

2. The end of the semicolon can be written without writing (multiple statements in the same line must be separated by semicolons)

3. Do not need to write the main function, directly from the top down execution

4. File suffix changed. Swift, no longer is. h and. m two files now

。。。。。。


Second, Playground

Playground as the name implies, play is meant to play, ground is the meaning of the place. Play, write demo or test very nice. Demonstrated playground live display on WWDC and demonstrated a simple mini-game.

the role of playground :

1. WYSIWYG, real-time display

2. Real-time viewing of UI controls

3. Real-time observation of the change of values, can draw a chart

Here are some of the test code written, WWDC on the same painting sine function. Direct and convenient.



Three, constants and variables

Declare constants with let (type following the article)

Let A = 10

declaring variables with Var

var B = 10


Four, string

The concatenation of strings is more like Java, but the types in swift do not add directly to each other.

At the same time, the string is not @ "" to write, but "". The type is string, not nsstring.

Concatenation of strings. (formerly stringWithFormat to Stitch strings) var str1 = "Xu" var str2 = "Neng" var str3 = str1 + "" + str2//string Insert variable var name = "Xiao Ming" var age = 10var result = "\ (name) is the age of \ (aged)!" var result = name + "Age is" + ages + "Old!"   This is wrong, and the types in swift cannot be added to each other.

Five, print out

NSLog no more, it's just about the same as Java.

Printing and output print ("Hello world!")   Do not wrap print println ("Hello world!")//Line wrap print let Teststr = "ABCDEFG" Print (TESTSTR)

Six, the variable name

The same rules apply to previous naming conventions, but the extension is wider. Chinese characters and expressions (not all) can be used.




Reference: the Swift programming Language

Reprint Please specify source: http://blog.csdn.net/xn4545945



Summary of playground, constants, variables, strings, etc. in "IOS" Swift

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.