Swift Learning notes a basic data type and simple statement syntax

Source: Internet
Author: User
Tags array definition

First Program

New Xcode project, language selection Swift

Once the project is established, it can be run directly command+r.
Modify the program Viewcontroller.swift

////Viewcontroller.swift//H?ello Swift////Created by Xie Han Festival on 15/6/9.//Copyright (c) 2015 WHR. All rights reserved.//ImportUIKitclassViewcontroller:uiviewcontroller {OverrideFunc Viewdidload () {Super. Viewdidload () print ("Hello Swift")additional setup after loading the view, typically from a nib.}OverrideFunc didreceivememorywarning () {Super. Didreceivememorywarning ()//Dispose of any resources, can be recreated.}}

After running, output Hello Swift.

You can see that the overall framework is very similar to OBJECTC and the syntax is different. It is strange that every line is useless;

Variable and logical syntax variable definition
varA= the                    //Variant type, VAR is used to define variablesA= - Letconstantvariable= -    //define a constantLeft double:double =Ten     //Specify constant typeString(constantvariable)//Type conversion, which is much more convenient than OC LetMerge="The first one is \ (a)"      the//string contains a valuevarlist=["a","B","C","D"]//Array definitionlist[1] ="B1"                     //array can be directly assigned to a value Letemptyarray=String[]()//define an empty array Letemptydictionary=dictionary<String,list> ()//define an empty dictionaryvarCannil:String? ="ABC"  //Optional
Cycle
foriteminlist{}遍历词典和数组for (itemin array{    forinitem{    }}
Conditions
ifa>10 {   //苹果为什么不搞和c java 类似的语法呢}ifa=b{}
Branch
switchstr{    case"a":    case"b":    default:}
Cycle
whilei<10{    i=i+1;}fori0...3{   print(i)}fori=0;i<3;++i{   print(i)}
Function
func hello(name:String)->String{   return"Hello \(name)"}

function allows nesting

Swift Learning notes a basic data type and simple statement 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.