本人買了一臺mac book pro專門學(xué)習(xí)Swift,以后會寫一些學(xué)習(xí)筆記發(fā)上來。學(xué)習(xí)資料主要蘋果官方發(fā)布的《The Swift Programming Language》,通過iBook可以找到。
今天學(xué)習(xí)了如何開始寫第一個Swif程序。
首先下載安裝Xcode 6,我目前用的是Xocde 6 beta 6。
打開Xcode,F(xiàn)ile -> New -> Playground創(chuàng)建一個playground,如下圖:
圖1:輸入文件名
圖2:選擇保存路徑
保存好后出現(xiàn)如下窗口:
上圖中,左邊是代碼編輯區(qū)域,右邊是實(shí)時顯示代碼效果的區(qū)域。在左邊每敲一行代碼,右邊都會實(shí)時顯示出來,不用編譯也不用運(yùn)行。真是很強(qiáng)大。這時就可以開始Swift之旅了。
這里對Playground進(jìn)行下介紹,Playground是用于快速開發(fā)和調(diào)試的,開發(fā)好后要把這些代碼要移到項(xiàng)目中。當(dāng)然也可以用來學(xué)習(xí)Swift。下面這段是蘋果網(wǎng)站對Playground的介紹。
Playgrounds enable the interactive experience of a script language, even though Swift compiles to highly-optimized native code. Type a line of code and the result appears immediately. If your code runs through a loop, add that line of code to the timeline assistant editor to watch its progression. Display variables in a graph, inspect each step when drawing a view, or watch an animated SpriteKit scene. When you’ve perfected your code in the playground, simply move it into your project. Playgrounds documentation includes tutorials that you can open in a playground, providing an interactive worksheet for experimentation.