在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
//集合类型 数组 字典 func array1(){ var arr = ["1","11","22","dd"] //简单写法 var arr1 = ["11","ee"] //数组拼接 数组 var arr3 = arr + arr1 //数组拼接 字符串 arr3.append("555") arr3 += ["444","44444"] print(arr3) //插入数据 arr3.insert("098", at: 3) //获取数组中的数据 let str1 = arr3[1] print(str1) //改变 数据 arr3[3] = "rrr" //改变多个 arr3[2...5] = ["222","77","333"] //删除数据 let strremo = arr3.remove(at: 2) // 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 = [11 : "eer" , 9 : "err"] //创建一个空字典 var kong = Dictionary<Int,String>() kong[0] = "111" print(kong) print(dict2) //变值 dict2[11] = "4567" dict2.updateValue("33", forKey: 9) //字典的遍历 for (iint,sttr) in dict2 { print("key:\(iint), value:\(sttr)") } //字典的删除 dic1.removeValue(forKey: "key") dict2.removeValue(forKey: 0) dict2.removeAll() } //枚举 enum dingyi { case jiage(Int,String) case miaoshu(String) } //使用 var jia = dingyi.jiage(10, "名字") 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 = "32443" st.s2 = "478" let ss = st.shuchu(inn: 4) let la = wedView() let laa = la.labelframe(x: 0, y: 0, width: 0, height: 0) 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: 20, y: 300, width: 100, height: 100) label.frame = CGRect(x: 10, y: 10, width: 100, height: 100) label.text = "wo\nshi\nyi个\nlabel" label.numberOfLines = 0 label.textColor = UIColor.black self.addSubview(label) return self } }
|
请发表评论