日常随笔第四弹

x-code中数组与字典的一些常用命令

var deer = 123  //var定义变量,let定义常量

struct deer1 {
    var number : Double
    var name : String
} //定义值类型

var xx = deer1 (number: 007 , name: "sb")
var cc = xx

print(xx.number)
print(cc.name)

xx.number = 008

print(xx.number)
print(cc.number)

class xxdeer{
    var name : String = "dashab"
    var number : Double = 007
}//定义引用类型

var rr = xxdeer()
var ee = rr

print(rr.name)
print(ee.name)

rr.name = "bushide"

print(rr.name)
print(ee.name)

var Arrayxx = [1,2,3,4,5] //定义数组

Arrayxx.removeAtIndex(4) //移除数组中的Arrayxx[4]

print(Arrayxx)

Arrayxx.append(45) //向数组中添加元素
print(Arrayxx)

var Arraydeer = [32,33,34]
var Arrayxx1 = Arrayxx + Arraydeer //将两个数组链接起来
print(Arrayxx1)

Arrayxx.insert(77, atIndex: 2) //在数组Arrayxx[2]位置增加一个元素77
print(Arrayxx)

var dictxx1 : [String : Int] = ["key1" : 34] //定义一个字典,键值对类型定义为字符串与整型
dictxx1 ["key2"] = 33 //有该键值对就对其修改,无则添加键值对
dictxx1 ["key1"] = 22
dictxx1.removeAtIndex(dictxx1.indexForKey("key1")!)

dictxx1.removeValueForKey("key2") //删除键值对
print(dictxx1)

var dictxx2 = [String:Int]()
var dictxx3: Dictionary
dictxx2 ["key7"] = 33
print(dictxx2)

你可能感兴趣的:(日常随笔第四弹)