SwiftのArrayとDictionary


スポンサーリンク

import UIKit

var str = "Hello, playground"

let myLabel = UILabel(frame: CGRectMake(0,0,200,50))
myLabel.backgroundColor = UIColor.redColor()
myLabel.text = "Hello, swift"
myLabel.font = UIFont(name: "Georgia", size: 24)
myLabel

//mutable array
var array1 :[String] = [String]()
array1.append("apple")
array1.append("gollila")

//imutable array
let array2 :[String] = [String]()

//this is error
//array2.append("apple")

let array3 :[String] = ["apple","gollila"]
print(array3[0])

//Dictionary
var mutableDic1 :[String:String] = [String:String]()
mutableDic1["apple"] = "small"
mutableDic1["golilla"] = "big"

mutableDic1["apple"]