In this post, we will share how to declare a function in Swift programming. This is a very basic program in Swift programming language. If you are Swift beginners or want to start learning Swift programming language, then this program will help you to understand the basic Swift programming.
Copy the below program and create a file named “SwitchProgramExample.swift” and execute it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() } override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) let alertController = UIAlertController(title: "Action Sheet", message: "What would you like to do?", preferredStyle: .ActionSheet) let sendButton = UIAlertAction(title: "Send now", style: .Default, handler: { (action) -> Void in print("Ok button tapped") }) let deleteButton = UIAlertAction(title: "Delete forever", style: .Destructive, handler: { (action) -> Void in print("Delete button tapped") }) let cancelButton = UIAlertAction(title: "Cancel", style: .Cancel, handler: { (action) -> Void in print("Cancel button tapped") }) alertController.addAction(sendButton) alertController.addAction(deleteButton) alertController.addAction(cancelButton) self.navigationController!.presentViewController(alertController, animated: true, completion: nil) } } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.