Swift学习笔记

入了Mac的坑开始学Swift。

以下是Swift的学习笔记。格式很乱,给自己看的。。


一、基本数据类型

常量和变量 let/var

Int/Double,Float/String/Bool/Tuples/Optionals

let A:int = 1

let B:String = “test”

let C:Bool = true

if C{

print(“true”)

}

ThisIsTuples = {true , 200 ,”ok”}

ThisIsTuples.1

let D:int?

D = 12


基本运算符

+ – * / %

var c =1

c++

++c

比较操作符

==/!=/</>/<=/>=/===/!==

条件运算符

score >=60?”及格”:”不及格”

a??b      a!=Nil?a!:b

区间运算符

[a,b]   a..b

[a,b)    a..<b

for i in 1…9{i*i*i}

for x in 0..<A.count{print(A[x])}


数组

var array = [“a”,”b”,”c”]存储同类型的数据
var array2:[String] = [“a”,”b”,”c”]
var array3:Array<String> = [“a”,”b”,”c”]

空数组 var array =[Int]()

数组的修改

array6.isEmpty
array6.count
array6.insert(6, at: 2)
array6.remove(at: 1)
array6.removeLast()
array6
array6[0…1]=[1,2,3,4]

 

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google photo

You are commenting using your Google account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s