我正在更新到Swift 2.0。
我的旧代码:
animateButtonsOnScreen(callback: completedImageEditingButtonSwap)
编译器想要的新代码:
animateButtonsOnScreen(callback: { completedImageEditingButtonSwap($0) })
callback:
没有参数。这个新的$ 0对象是什么?我没有参数,所以它在这里引用了什么?
注意:编译器说这是我希望我使用这种新语法
使用闭包来安全地包装对函数的调用
使用某些代码进行更新
func swapButtonsForImageCapture()
{
if(DeviceProperties.isIphone4() == true)//iPhone 4s needs smaller icon
{
_takePhotoButton.setImage(UIImage(named: "snapimageicon4s"), forState:UIControlState.Normal)
}else
{
_takePhotoButton.setImage(UIImage(named: "snapimageicon"), forState:UIControlState.Normal)
}
_takePhotoButton.removeTarget(nil, action: nil, forControlEvents: UIControlEvents.AllEvents)
_takePhotoButton.addTarget(_controller, action: Selector("takePhoto:"), forControlEvents: UIControlEvents.TouchUpInside)
let buttonsToAnimateOut:[UIButton] = [_textButton,_filtersButton,_previewButton]
animateButtonsOffScreen(buttonsToAnimateOut, callback: { self.swapButtonsForImageCapturePart2($0) })
}
func swapButtonsForImageCapturePart2()
{
let buttonsToAnimateIn:[UIButton] = [_swapCameraButton,_flashButton,_galleryButton]
animateButtonsOnScreen(buttonsToAnimateIn, callback: { self.completedImageCaptureButtonSwap($0) })
}