iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 7
1
Mobile Development

iOS App初心者的30天試鍊系列 第 7

Day7:今天我們來玩一下程式員的遊樂場-Play Ground

在我們介紹完好幾天的UI及各式View Controller後 , 接下來我們來談一程式設計師

的遊樂園--Play Ground

當我們開啟Xcode啟動畫面時 , 映入眼簾會看到Get started with a playground

關鍵字

https://ithelp.ithome.com.tw/upload/images/20190914/20112182H306JcX4Yk.png

直接點選 , 選擇Blank Template , 接著我們就可以開始撰寫程式碼及測試看結果

https://ithelp.ithome.com.tw/upload/images/20190914/20112182lqnVTOeqPT.png

設定Play Ground存檔名稱

https://ithelp.ithome.com.tw/upload/images/20190914/20112182sNOFb7AhNH.png

以下為程式碼編輯區塊及結果即時顯⽰區塊,寫完程式碼按下左下角的藍⾊三⾓形執行

,如下圖

https://ithelp.ithome.com.tw/upload/images/20190914/20112182eb52ynz4XG.png

我們可以在Play Ground執行簡單的數學運算即可得到以下結果

https://ithelp.ithome.com.tw/upload/images/20190914/201121827n6893R9Ke.png

在這裡加減乘除我們稱之為operator(運算子),

operator(運算子)作⽤的對象稱之為operand(運算元)

https://ithelp.ithome.com.tw/upload/images/20190915/20112182g0hsnqrmSR.png

程式執行有右邊的特性 : 由上而下,由左⽽而右

接下來我們來談一下字串,字串是由很多字組合串在一起,必須以" "包起來

https://ithelp.ithome.com.tw/upload/images/20190915/20112182SIHPtrR3dw.png

程式碼裡的註解可分為單行及多行,單行在程式碼的表示為// ,選取多行文字後,

可用 cmd + / 快速注解

多行在程式碼表示為/ *
*/

https://ithelp.ithome.com.tw/upload/images/20190915/20112182QwzNuaRCBD.png

接下來宣告常數(constant)存東⻄,用let開頭來指定

let number = 7
let age = 25
let height = 175

https://ithelp.ithome.com.tw/upload/images/20190914/20112182Lcw9O0whUt.png

記得常數指定名稱大小寫是有差別的 , 不要以為是一樣的 ,切記

https://ithelp.ithome.com.tw/upload/images/20190915/20112182oXMsMvGSTO.png


上一篇
Day6:今天來聊聊如何使用Scroll View
下一篇
Day8:來談一下Swift裡的型別(Type)及Function
系列文
iOS App初心者的30天試鍊31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言