Syntax of Block in Swift

前端 未结 5 1346
南笙
南笙 2020-12-17 14:18

I am trying to rewrite from Objective-C to Swift, I cannot work out the syntax or understand the docs

Here is a simplified example in Objective-C I wrote:

         


        
5条回答
  •  半阙折子戏
    2020-12-17 14:52

    This is the swift closure format:

    {(parameter:type, parameter: type, ...) -> returntype in
        //do stuff  
    }
    

    This is what you should do:

    //The animation closure will take no parameters and return void (nothing).
    UIView.animateWithDuration(duration: NSTimeInterval, animations: {() -> Void in
        //Animate anything.
    })
    

    Here is the documentation for closures.

提交回复
热议问题