码迷,mamicode.com
首页 > 编程语言 > 详细

Swift 语法笔记01

时间:2016-05-14 21:32:04      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:

Swift 好多新奇的地方啊。。。妈的

 

var display: int {

  get()

  set()

}

 

Tuple:

let x: (d:Double, e:String, f:Int) = (3.1415, "Hello", 1)

x.d x.e x.f

let (a,b,c) = x

print(a,b,c)

 

Range:

let array=["a","b","c","d","e"]

let subArray1 = array[2...4] // c d e

let subArray2 = array[2..<4] // c d

比python的字符串[::]还是要差一点

for lop in 1...100 //打印从1到100

 

swift里的class是传引用的(和java一样),函数等可以更改传入类的成员的值

class foo {
    var value:Int = 100
}

func add (f: foo) {
    f.value += 1
}

let test = foo()
add(test)
test.value

 

Array:

var a = Array<String>()

or

var a = [String]()

 

filter map reduce

 

Dictionary

var dic = Dictionary<String, Int>()

var dic = [String: Int]()

Swift 语法笔记01

标签:

原文地址:http://www.cnblogs.com/makejeffer/p/5493206.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!