更新到Swift3.0后有些差异是需要我们重新了解的。
Swift 3改变可以分为两个大的部分
移除在Swift 2.2中弃用的方法语言更加安全,优雅1、Range Range在Swift3.0的初始化方式有所不同
var range:Range<Int> = Range(uncheckedBounds: (0,5))//结果通[0..<5]一致Range初始化方法需要我们传入一个元祖,一个最小值和一个最大值
public init(uncheckedBounds bounds: (lower: Bound, upper: Bound))2、ClosedRange
var range:ClosedRange<Int> = ClosedRange(uncheckedBounds: (0,5))//结果通[0...5]一致3、replaceSubrange
//闭区间//method1var array2 = [2,1,2]array2.replaceSubrange(ClosedRange(uncheckedBounds:(0,1)), with: [1])//method2array2.replaceSubrange(CountableClosedRange(uncheckedBounds:(0,1)), with: [1])//开区间//method3array2.replaceSubrange(Range(uncheckedBounds:(0,2)), with: [1])//method4array2.replaceSubrange(CountableRange(uncheckedBounds:(0,2)), with: [1])通过对比了解到method1和method2结果一致,method3和method4结果一致。
4、inout
//数据交换func swap( a:inout Int , b:inout Int){ let c = a a = b b = c}var x = 2,y = 3swap(&x, &y)新闻热点
疑难解答