Functions are essential for grouping blocks of tasks together. In this video, create a few simple functions to get familiar with the new syntax.
- [Narrator] Now that we've got our…control flow basics down,…let's move on to writing functions.…I'm going to go into my Adventureswift_Working folder,…and open up chapter six.…Functions are blocks of code…that we can define and call by name to perform whatever…tasks we've coded into them.…Let's write our first function here,…and we'll keep it super simple.…We start with the func keyword,…and then you name it.…
So we are going to name our function saluteHunter.…Now you need to add an open and close parenthesis,…and open and close curly braces.…Now we will get into this in a bit,…but those parenthesis are where our parameters would go…if we had any.…You can think of parameters as inputs…and return values as outputs.…So in our saluteHunter,…we are just going to have a print statement.…This is going to say, 'Hello there intrepid Hunter'.…
To call any function, you just use it's name.…So here saluteHunter and open and close parenthesis.…The next code will usually complete that for you.…So here in our debug log we've got,…
Author
Released
11/9/2017- Starting new playgrounds and projects
- Variables and constants
- Writing single and multiline comments
- Core string methods
- Working with numbers
- Working with collections
- Creating arrays
- Working with sets
- Application control flow
- Writing functions
- Basic Swift classes and structs
Skill Level Beginner
Duration
Views
Related Courses
-
Swift: Writing Testable Code
with Mark DiFranco3h 11m Intermediate -
Swift 4: Protocol-Oriented Programming
with Károly Nyisztor1h 44m Intermediate
-
Introduction
-
Welcome46s
-
-
1. Getting Started
-
Getting Xcode38s
-
-
2. Swift 101
-
Swift retrospective1m 12s
-
Accessing documentation1m 13s
-
Value vs. reference types2m 56s
-
-
3. Variable Basics
-
Variables and constants2m 37s
-
Logging and commenting1m 49s
-
Swift operators5m 19s
-
Basic strings3m 59s
-
Core string methods5m 43s
-
Working with numbers3m 27s
-
Basic Booleans1m 35s
-
Chapter solution3m 28s
-
-
4. Working with Collections
-
Swift arrays5m 7s
-
Core array methods5m 45s
-
Swift dictionaries5m 44s
-
Core dictionary methods5m 31s
-
Working with sets5m 17s
-
Core set methods3m 4s
-
Swift tuples5m 10s
-
Chapter solution4m 54s
-
-
5. Application Control Flow
-
The if statement3m 18s
-
Chaining optionals3m 20s
-
Using for-in loops3m 26s
-
While loops2m 55s
-
The switch statement6m 40s
-
The guard statement6m 29s
-
Chapter solution4m 36s
-
-
6. Writing Functions
-
Basic functions3m 51s
-
Complex functions6m 1s
-
Overloading functions2m 15s
-
Function types3m 45s
-
Understanding closures6m 33s
-
Type aliasing3m 58s
-
Chapter solution4m 51s
-
-
7. Classes and Structs
-
Basic Swift classes9m 7s
-
Basic Swift structs2m 53s
-
Adding struct methods3m 55s
-
Swift enumeration basics2m 29s
-
Introduction to protocols5m 57s
-
Challenge solution4m 14s
-
-
Conclusion
-
Next steps50s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Basic functions