在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ 直接上代码,给你个眼神,自己领悟! 1 //Set排序 2 let stringSet1 = Set(["car", "boat", "bike", "toy"]) 3 let stringArray1 = stringSet1.sorted() 4 print(stringArray1) 5 // will print ["bike", "boat", "car", "toy"] 6 7 //Set去除元素第一位不为b字母的元素 8 let stringSet2 = Set(arrayLiteral: "car", "boat", "car", "bike", "toy") 9 let stringArray2 = stringSet2.filter { $0.characters.first != "b" } 10 print(stringArray2) 11 // may print ["car", "toy"] 12 13 //Set<Int>转换为[String] 14 let intSet3 = Set([1, 3, 5, 2]) 15 //方法一:flatMap 16 let stringArray3 = intSet3.flatMap { String($0) } 17 print(stringArray3) 18 //方法二:Array 19 let stringArray4 = Array(intSet3) 20 print(stringArray4) 21 // may print ["5", "2", "3", "1"] 22 23 //Set<Int>转换为[Int] 24 let intSet5 = Set([1, 3, 5, 2]) 25 let intArray5 = intSet5.map { $0 } 26 print(intArray5) 27 // may print [5, 2, 3, 1]
|
请发表评论