ios - Different types of closure syntax in swift - which one is correct? -


i'm pretty curious 1 of these syntax statements (more) correct. playground happily compiles both cases.

method 1

// copied , appears clear me uiview.animate(     withduration: 3.0,     animations: {      },     completion: { (bool) in         // completion code     } ) 

method 2

uiview.animate(     withduration: 3.0,     animations: {          // code      }) {(bool) in       // code when finished?       // argument label completion missing?     } 

why rounded brackets in 2nd method closed before last argument stated? or implementation of uiview.animation?

the difference between both methods following:

method 1: regular closure

method 2: trailing closure. last closure parameter in signature of function can written in shorter syntax. if second parameter completion, , animations parameter last, trailing closure apply animations etc. has stand last (or only) closure parameter.

if miss completion label, free type this:

uiview.animate(withduration: 3.0, animations: {   }) {(completion: bool) in   } 

for completion of question well: same implementation of identical function, different syntax.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -