Swift 編程語言本身實踐 -本身在Xcode6 動手寫20140603

  Swift 是什麼,你們都回去百度或者Google,有的甚至認爲是Taylor Swift(她是個人偶像),可是若是今天在百度百科裏搜索絕對沒有說是Apple最新推出的編程語言,由於是在2014年6月3日凌晨1點多(北京時間)在2014年WWDC上發佈的,它會在將來逐步替代Objective-C開發語言,這讓咱們學了Objective-C的人又要學習新的編程語言,給你們看張圖片:這是你們的感覺!express

可是咱們還要去學習Swift!畢竟將來不落後這個時代!編程

Swift是什麼?

Swift是蘋果於WWDC 2014發佈的編程語言,這裏引用The Swift Programming Language的原話:swift

Swift is a new programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility.數組

Swift adopts safe programming patterns and adds modern features to make programming easier, more flexible and more fun.app

Swift’s clean slate, backed by the mature and much-loved Cocoa and Cocoa Touch frameworks, is an opportunity to imagine how software development works.框架

Swift is the first industrial-quality systems programming language that is as expressive and enjoyable as a scripting language.編程語言

簡單的說:性能

  1. Swift用來寫iOS和OS X程序。(估計也不會支持其它屌絲系統)
  2. Swift吸收了C和Objective-C的優勢,且更增強大易用。
  3. Swift可使用現有的Cocoa和Cocoa Touch框架。
  4. Swift兼具編譯語言的高性能(Performance)和腳本語言的交互性(Interactive)。

Swift語言概覽

複製代碼

 1 // Playground - noun: a place where people can play
 2 
 3 import Cocoa
 4 
 5 var str = "Hello, playground"
 6 var str1 = "Hello Wrold!!!"
 7 var str2 = "O(∩_∩)O哈哈~"
 8 
 9 // Hello, world
10 println("Hello, world")
11 
12 
13 // 變量與常量
14 // Swift 使用 var 聲明 變量 , let 聲明常量
15 var myVariable = 42
16 myVariable = 50
17 let myConstant = 42
18 
19 // 類型推導
20 let explicitDouble : Double = 70
21 
22 // Swift 不支持隱式 類型轉換 (因此須要顯式類型轉換)
23 let label = "The width is"
24 let width = 94
25 let width1 = label + String(width)
26 
27 // 使用 \(item) 的形式進行 字符串格式化
28 let apples = 3
29 let orages = 5
30 let sum = "I have \(apples) apples."
31 let sum1 = "I have \(apples + orages) pieces of fruit."
32 
33 // 數組和字典
34 // Swift 使用[] 操做符聲明 數組(array)和字典 (dictionary)
35 var listArr = ["fish","water","apple","rice"]
36 listArr[1] = "bottle of water"
37 
38 var dict = [
39     "name": "melody",
40     "age" : "26",
41 
42 ]
43 dict["sex"] = "female"
44 
45 // 通常使用初始化器(initializer)語法建立空數組和空字典
46 
47 let emptyArray = String[]()
48 let emptyDict = Dictionary<String, Float>()

看看我在Xcode 6上編程的效果:學習

這個我也在學習,但願你們多多支持,多多在文章下寫評論和點推薦,個人郵箱爲lkvt@sina.com!
相關文章
相關標籤/搜索