swift數組初始化,插入,刪除

var arr:String[] = ["hello","world"] //初始化一個string類型的數組
arr.insert("hi",atIndex:1)    //插入一條記錄到數組的某一位置
arr.append("sam")             //插入一條記錄到數組末尾
arr += ["sam","code"]         //合併數組
arr.removeAtIndex(0) //刪除一條記錄
arr.count //數組長度
for temp in arr{ //數組遍歷
    println(temp)
}

for (i , temp) in enumerate(arr){
    println("\(i)  \(temp)")   
}
相關文章
相關標籤/搜索