Swift 3.0変わったことさっくり

元ネタ https://www.hackingwithswift.com/swift3

All function parameters have labels unless you request otherwise

before

names.indexOf("Taylor")

after

names.index(of: "Taylor")

UIKit系はこうなる

override func viewWillAppear(_ animated: Bool)

Omit needless words

before

let blue = UIColor.blueColor()

after

let blue = UIColor.blue()

UpperCamelCase has been replaced with lowerCamelCase for enums and properties

  • CGColorとかがcgColorになる
  • enum caseもlowerCamelCaseになる
let red = UIColor.red().cgColor

§

enum caseにOptionalを指定すると中身がnilだった時に小文字に逃げる?ようになる?

You get the idea. However, this tiny change brings something much bigger because Swift's optionals are actually just an enum under the hood, like this:

enum Optional {
    case None
    case Some(Wrapped)
}
This means if you use .Some to work with optionals, you'll need to switch to .some instead. Of course, you could always take this opportunity to ditch .some entirely – these two pieces of code are identical:

for case let .some(datum) in data {
    print(datum)
}

for case let datum? in data {
    print(datum)
}

Swifty importing of C functions

インスタンスメソッドになった?

if let ctx = UIGraphicsGetCurrentContext() {
    let rectangle = CGRect(x: 0, y: 0, width: 512, height: 512)
    ctx.setFillColor(UIColor.red().cgColor)
    ctx.setStrokeColor(UIColor.black().cgColor)
    ctx.setLineWidth(10)
    ctx.addRect(rectangle)
    ctx.drawPath(using: .fillStroke)

    UIGraphicsEndImageContext()
}

Verbs and nouns

myArray.enumerate()
myArray.enumerated()

myArray.reverse()
myArray.reversed()

dがついた、とか

Swift 2.2のsort()は非破壊的だけど3.0は破壊的になる?