Join Harrison Ferrone for an in-depth discussion in this video Complex functions, part of Learning Swift 3 for Developers.
- [Instructor] Let's start off by making…some new room and adding a comment.…Complex functions.…We're going to write one more variation…of our current date example,…except this time we're going to use…an optional type as our parameter.…Func current date with optional…and we're still going to use the message input…of type string optional, open and close curly brackets.…
In here, since message isn't optional we need to unwrap it.…Inside the function we need…to unwrap our message string optional.…Use if let text equals message…curly brace, close curly brace…and in here we're just going to print it's 3/21/2017…and we're going to insert our unwrapped message.…We need an else for if we actually have a nil value,…we're going to print out it's 3/21/2017,…but no valid message.…
Let's call our new function and see what happens.…We've got an optional here, I'm going to pass in nil…and we see our debug log says no valid message.…If we changed our message to Harrison,…we'd get our first print out.…Now that we have a lot of the building blocks covered,…
- Starting a new playground
- Printing to the console
- Declaring variables
- Working with numbers
- Using strings
- Breaking down optionals
- Understanding closures
- Classes vs. structs
- Extensions and protocols
Skill Level Beginner
1. Hello Swift
2. Back to Basics: Variables and Operators
3. Collections, Tuples, and Enumerations
4. Working with Logic Flows
5. Only in Swift: Optionals
6. Functions, Closures, and Associated Types
7. Classes vs. Structs
8. Advanced Topics
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take 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.