Swift2.2更新内容(简介)

1.允许大多数关键字作为方法中参数名,let、var、inout除外。

before:

func touchesMatching(phase: NSTouchPhase,`in` view: NSView?) -> Set

now:

func touchesMatching(phase: NSTouchPhase,in view: NSView?) -> Set

2.用associatedtype代替typealias用于相关类型声明,typealias依然可以用于为现有类型替代名称。

before:

protocol Prot {
    typealias Container : SequenceType
}
extension Prot {
    typealias Element = Container.Generator.Element
}

now:

protocol Prot {
    associatedtype Container : SequenceType
}
extension Prot {
    typealias Element = Container.Generator.Element
}

3.为了使 AnySequence的delegate调用底层的序列, 它的初始化器会有格外的约束。

before:

public struct AnySequence : SequenceType {
  public init<
    S: SequenceType
    where
      S.Generator.Element == Element
  >(_ base: S) { ... }
}

now:

public struct AnySequence : SequenceType {
  public init<
    S: SequenceType
    where
      S.Generator.Element == Element,
      S.SubSequence : SequenceType,
      S.SubSequence.Generator.Element == Element,
      S.SubSequence.SubSequence == S.SubSequence
  >(_ base: S) { ... }
}

4.元组有了操作符。

let a:(String,Int) = ("123",123)
let b:(String,Int) = ("123",123)
a == b //true

5.为Swift的版本进行配置

#if swift(>=2.2)
print("Active!")
#else
    this! code! will! not! parse! or! produce! diagnostics!
#endif

6.改变了有参数的函数的命名方式。

举个例子:

extension UIView {
  func insertSubview(view: UIView, at index: Int)
  func insertSubview(view: UIView, aboveSubview siblingSubview: UIView)
  func insertSubview(view: UIView, belowSubview siblingSubview: UIView)
}
someView.insertSubview(view, at: 3)
someView.insertSubview(view, aboveSubview: otherView)
someView.insertSubview(view, belowSubview: otherView)

before:

let fn = someView.insertSubview // ambiguous: could be any of the three methods

now:

let fn = someView.insertSubview(_:at:)

7.引用了OC的方法选择器

before:

 button.addTarget(self, action: "test", forControlEvents: UIControlEvents.AllEvents)

now:

 button.addTarget(self, action: #selector(ViewController.test), forControlEvents: UIControlEvents.AllEvents)

你可能感兴趣的:(Swift2.2更新内容(简介))