标签:import ios ble tin 替换 uikit bool app index
import UIKit
var a:[Int] = [1,2,3,4]
print(a)//[1, 2, 3, 4]
for index in 0..<a.count{
print(a[index])//1234
}
var b = ["hello","world","123"]//涉及到类型推断
print(b)//["hello", "world", "123"]
b+=["iOS","MacOS"]//字符串的拼接
print(b)//["hello", "world", "123", "iOS", "MacOS"]
b.insert("apple", at: 1)//字符串的插入
print(b)//["hello", "apple", "world", "123", "iOS", "MacOS"]
print(b.contains("hello"))//true。元素的查找
b.replaceSubrange(0...1, with: ["123","456"])//元素替换
print(b)//["123", "456", "world", "123", "iOS", "MacOS"]
b.remove(at: 0)//元素的删除
print(b)//["456", "world", "123", "iOS", "MacOS"]
var c:Array<Double> = [1.1,2.2,3.3]//范型为Double
print(c)//[1.1, 2.2, 3.3]
c[0] = 5.5//元素的修改
print(c)//[5.5, 2.2, 3.3]
c.append(6.6)
print(c)//[5.5, 2.2, 3.3, 6.6]
var d = Array(repeating: -1, count: 3)
print(d)//[-1, -1, -1]
import UIKit
var a = [1,2,3,4,5,6]
a.sort(by: {(s1,s2)->Bool in
if (s1>s2) {
return true
}else{
return false
}
})
print(a)//[6, 5, 4, 3, 2, 1]。元素的倒序排列
var b = [1,3,2,7,5]
b.sort()//数据的元素排序
print(b)//[1, 2, 3, 5, 7]
import UIKit
var a = [1,2,3,4,5,6]
var b = a.filter({(item)->Bool in
if (item != 3) {
return true//
}else{
return false
}
})
print(a)//[1, 2, 3, 4, 5, 6]
print(b)//[1, 2, 4, 5, 6]
import UIKit
var a = [1,2,3]
var b = [1,2,3]
var c = [4,5,6]
print(a==b)//true
print(a==c)//false
标签:import ios ble tin 替换 uikit bool app index
原文地址:https://www.cnblogs.com/yangyh26/p/11826038.html