0%

  1. 生成新的 SSH 秘钥(记得输入 passphrase 口令):

    1
    2
    3
    $ ssh-keygen -t rsa -C "YOUR_EMAIL@YOUREMAIL.COM" -f ~/.ssh/github_rsa
    $ ssh-keygen -t rsa -C "YOUR_EMAIL@YOUREMAIL.COM" -f ~/.ssh/gitcafe_rsa
    $ ssh-keygen -t rsa -C "YOUR_EMAIL@YOUREMAIL.COM" -f ~/.ssh/oschina_rsa
    阅读全文 »

类和结构体的对比

定义语法:

1
2
3
4
5
6
7
8
9
10
struct Resolution {
var width = 0
var height = 0
}
class VideoMode {
var resolution = Resolution()
var interlaced = false
var frameRate = 0.0
var name: String?
}
阅读全文 »

闭包表达式

闭包表达式语法:

1
2
3
4
5
6
7
8
9
10
11
12
let names = ["Chris", "Alex", "Ewa", "Barry", "Daniella"]

func backwards(s1: String, s2: String) -> Bool {
return s1 > s2
}

var reversed = sorted(names, backwards)
// reversed is equal to ["Ewa", "Daniella", "Chris", "Barry", "Alex"]

reversed = sorted(names, { (s1: String, s2: String) -> Bool in
return s1 > s2
})
阅读全文 »

函数的定义与调用

函数定义:

1
2
3
4
func sayHello(personName: String) -> String {
let greeting = "Hello, " + personName + "!"
return greeting
}
阅读全文 »

for循环

for-in(数组,集合,字典,字符串类似):

1
2
3
4
5
6
7
8
for index in 1...5 {
println("\(index) times 5 is \(index * 5)")
}
// 1 times 5 is 5
// 2 times 5 is 10
// 3 times 5 is 15
// 4 times 5 is 20
// 5 times 5 is 25
阅读全文 »

数组

创建空的数组:

1
2
3
var someInts = [Int]()
println("someInts is of type [Int] with \(someInts.count) items.")
// prints "someInts is of type [Int] with 0 items."

添加数组数据项:

1
2
3
4
someInts.append(3)
// someInts now contains 1 value of type Int
someInts = []
// someInts is now an empty array, but is still of type [Int]
阅读全文 »

字符串字面量

1
let someString = "Some string literal value"

初始化空字符串

1
2
3
var emptyString = ""               // empty string literal
var anotherEmptyString = String() // initializer syntax
// these two strings are both empty, and are equivalent to each other
阅读全文 »

赋值运算符

1
2
3
4
let b = 10
var a = 5
a = b
// a is now equal to 10

算术运算符

1
2
3
4
5
1 + 2       // equals 3
5 - 3 // equals 2
2 * 3 // equals 6
10.0 / 2.5 // equals 4.0
"hello, " + "world" // equals "hello, world"
阅读全文 »

常量和变量

用let来声明常量,用var来声明变量:

1
2
let maximumNumberOfLoginAttempts = 10
var currentLoginAttempt = 0

类型标注:

1
2
var welcomeMessage: String = "Hello"
var red, green, blue: Double

输出常量和变量:

1
2
var friendlyWelcome = "Hello!"
println("The current value of friendlyWelcome is \(friendlyWelcome)")
阅读全文 »