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!
相关文章
相关标签/搜索