简体   繁体   中英

Swift Functions

Only started learning programming in general 3 days ago, and I'm not sure how parameters and returns of functions work - if I call, for example

@IBAction func button() {
    dismiss(animated:true, completion:nil)
}

What is that actually doing?

What I understand is (not sure if I'm right) dismiss is a function that is built into the UIKit, and I am inputting a parameter "animated", and setting it to "true", and the same goes for the "completion" parameter.

What does this even mean? What am I doing here in relation to what the function does?

All I know is that it means I am allowing an animation to occur when the button is clicked on, and that nothing will happen (since it's "nil") after I click on the button (I will dismiss the screen or something?)

@IBAction func button() {
    dismiss(animated:true, completion:nil)
}

I am new in Programming. I will tell you what I know. This means when you clicked a ( button ) the viewController will return to the previous viewController. For instance. when you click a page and then you want to return to the previous page ( back button ). hope it will help you. I can not help you with this ( completion:nil ) because I am new too . haha
Sorry.

Look here for definition of dismiss in that context.

I suggest that you start your learning with Swift Playground and learn using functions and other elements of the Swift language separately from Cocoa Touch (the UI API which is used in your example). It adds a whole another level of complexity.

dismiss(animated:true,completion:nil)

如果您呈现它,它将关闭当前的viewController。如果您将animation设置为true,它将在关闭时显示动画。对于完成,它是一个闭包,在完成后将被调用。有关闭包的信息,请访问https:// developer。 apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM