0

raywenderlich の記事から、次のコード スニペットを見ました。

 // new way, Swift 3
 if let ctx = UIGraphicsGetCurrentContext() {

  let rectangle = CGRect(x: 0, y: 0, width: 512, height: 512)
    ctx.setFillColor(UIColor.blue().cgColor)
    ctx.setStrokeColor(UIColor.white().cgColor)
    ctx.setLineWidth(10)
    ctx.addRect(rectangle)
    ctx.drawPath(using: .fillStroke)

    UIGraphicsEndImageContext()
}

初期化中に変数(ctx)自体にアクセスできるのはなぜですか? 前もって感謝します。

4

2 に答える 2