VWang
VWang

Reputation: 193

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?)

Upvotes: 0

Views: 75

Answers (3)

Yu On
Yu On

Reputation: 107

@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.

Upvotes: 1

Mahesh Giri
Mahesh Giri

Reputation: 1840

dismiss(animated:true,completion:nil)

It will close current viewController if you are presenting it.If you pass animated as true the it will show animation while dismissing.For completion it is an closure which will be called after completion To read about closures here is link https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html

Upvotes: 0

MirekE
MirekE

Reputation: 11555

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.

Upvotes: 0

Related Questions