Monday, August 11, 2014

2.3 我的第一個swift程式

2.3 我的第一個swift程式


STEP1:建立一個全新playground運動場程式專案


Application 中,選取Xcode,在進入”Xcode 的歡迎視窗”後,請選取”Get started with a playground”,來建立一個全新playground運動場程式專案。


12


 


 


 


 


 


12 樣板專案執行的效果。


STEP2:決定儲存的位置


接下來決定儲存檔案位置。13


13 儲存的位置


STEP3:進入playground運動場程式模式


進入Xcode 程式環境下的playground運動場程式模式。14


14 進入playground運動場程式模式


STEP4:進入playground運動場程式模式


請輸入以下的程式。


範例 2-1 MyPlayground.playground


  1. import Cocoa // 加入函式庫定義Cocoa


  2. var str = “Hello, playground” // 變數str 設定資料為“Hello, playground”

  3. println(” How are you?”) // 顯示文字

  4. println(str)

  5. var a1=10 // 設定變數a1

  6. a1=a1+1 //a1加上1

  7. STEP5:程式執行


    會發現當撰寫swuft 時,右邊的畫面便會把的相關的變數結果顯示在畫面上,


    而如果要執行的程式,請點選右圖的任何資料中的圓圈。15


    15 修改後的程式畫面


    STEP5:Console Output 視窗


    整個程式執行的結果,就會在右邊出現Console Output 視窗,如果要關閉的話,請點選右上角的”x”按鍵,就可以關閉掉。


    16


    16 出現Console Output視窗


    執行結果:


    這個程式的執行結果,會出現二筆文字分別是


    How are you


    Hello, playground


     


    17


    17 執行結果。



    2.3 我的第一個swift程式

No comments:

Post a Comment