//集合类型 数组 字典
func array1(){ var arr = ["","","","dd"]
//简单写法
var arr1 = ["","ee"]
//数组拼接 数组
var arr3 = arr + arr1
//数组拼接 字符串
arr3.append("") arr3 += ["",""] print(arr3)
//插入数据
arr3.insert("", at: ) //获取数组中的数据
let str1 = arr3[]
print(str1) //改变 数据
arr3[] = "rrr" //改变多个
arr3[...] = ["","",""] //删除数据
let strremo = arr3.remove(at: ) // strrmo = 删除的数据 arr3.removeLast()
arr3.removeFirst()
arr3.removeAll() //遍历
arr3 += ["rr","ee","eww"] for strr in arr3 {
print(strr)
} } //字典
func dict() {
//创建 字典key value 可以是任意基本类型int string double bool
var dic1 = ["key" : "value","key1" : "value2"] var dict2 = [ : "eer" , : "err"] //创建一个空字典
var kong = Dictionary<Int,String>() kong[] = "" print(kong) print(dict2)
//变值
dict2[] = ""
dict2.updateValue("", forKey: ) //字典的遍历
for (iint,sttr) in dict2 {
print("key:\(iint), value:\(sttr)") } //字典的删除
dic1.removeValue(forKey: "key")
dict2.removeValue(forKey: )
dict2.removeAll() } //枚举
enum dingyi {
case jiage(Int,String)
case miaoshu(String)
} //使用
var jia = dingyi.jiage(, "名字") enum CompassPoint {
case North
case South
case East
case West
}
//或者用,隔开
enum com{ case n,s,e,w
} //函数。
//返回一个值 多个
func funcc( intt:Int,str:String) -> (Int,String) { return (intt,str) } func fffff(external exter:Int) -> Int { return exter; } //类的使用
class ViewController: UIViewController { override func viewDidLoad() {
super.viewDidLoad() let st = stringstring()
st.s1 = ""
st.s2 = "" let ss = st.shuchu(inn: ) let la = wedView() let laa = la.labelframe(x: , y: , width: , height: ) self.view.addSubview(laa)
} class stringstring { var s1 : String = "" var s2 : String = "" func shuchu(inn:Int) -> Int { return inn * inn
} } class wedView: UIView { var label = UILabel() func labelframe(x:Float,y:Float,width:Float,height:Float) -> UIView { self.backgroundColor = UIColor.gray
self.frame = CGRect(x: , y: , width: , height: )
label.frame = CGRect(x: , y: , width: , height: ) label.text = "wo\nshi\nyi个\nlabel"
label.numberOfLines =
label.textColor = UIColor.black
self.addSubview(label) return self } }