Swift初探一

來源:互聯網
上載者:User

標籤:

今天安裝了一下Xcode6-Beta版,想來體驗一下Swift的魅力:安裝Swift系統最低版本號碼為:10.9.3

僅僅看看一點The Swift Programming Language,以下給大家分享一下:(待續。。。)

// Playground - noun: a place where people can playimport Cocoa///1.聲明一個可變的變數var str = "Hello, playground"///2.聲明常量let implicitInteger=70let implicitDouble=70.0//3.明白聲明一個變數    變數名:類型=初值let explicitDouble:Double=70  //明白聲明一個Double變數let explicitFloat:Float=4///4. 類型轉換let label="The width is"let width=94let widthLabel=label+" "+String(width)  //強制類型轉換///5.  使用 \() 字串中包括變數let apples=3let oranges=5let appleSummary="I have \(apples) apples"let fruitSummary="I have \(apples+oranges) pieces of fruit."///6.使用[] 聲明一個數組或者字典//6.1聲明一個數組var names=["Lves Li","WildCat","LeLe"]var lele=names[2]  //獲得數組內容names[1]="Cat"     //改變數組中的元素names   // ["Lves Li","Cat","LeLe"]//6.2聲明一個字典var info=[    "Lves Li":"美男紙",    "WildCat":"帥鍋",    "Lele":"碼農"]var lInfo=info["Lele"]info["Lves"]="程式員"info   // [Lves: 程式員, Lves Li: 美男紙, WildCat: 帥鍋, Lele: 碼農]//6.3建立一個空的數組或者字典let emptyArray=String[]()let emptyDictionary=Dictionary<String,Float>()var shoppingList=[]  //聲明一個空的數組


官方建議使用Playground 能夠不用編譯 即時查看效果:



轉載請註明,本文轉自:http://blog.csdn.net/wildcatlele  未完待續。。。


Swift初探一

相關文章

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.