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