From the course: Swift 6 Essential Training
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Complex functions - Swift Tutorial
From the course: Swift 6 Essential Training
Complex functions
- [Instructor] Functions in Swift can go from simple to complex very quickly. When we start adding in multiple return types, optionals, and even default values. Let's revisit optionals here and add a new function. I'm going to call this setupArenaMatch, with no input parameters, but it is going to return an optional boolean. I'm going to return false here by default, but that can also now hold true or nil. Being the swift programmers that we are, we're going to use our trustee if let statement to unwrap the optional boolean. So we'll say, if let initSuccess, and we just call setupArenaMatch, open and close curly braces and we'll just print out Level initialized and our correctly unwrapped optional. If there's a nil value, we'll handle that too, with else and we'll print out, "Something went terribly wrong." Perfect, now our level initialized is false. We see that in the debug, but we can also change our return value…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Leveling the playing field30s
-
(Locked)
Basic functions3m 25s
-
Overloading functions3m 12s
-
(Locked)
Complex functions5m 9s
-
(Locked)
Function types3m 25s
-
(Locked)
Understanding closures4m 43s
-
(Locked)
Using Closures IRL5m 9s
-
(Locked)
Type Aliasing2m 51s
-
(Locked)
Challenge: Battlegrounds37s
-
(Locked)
Solution: Battlegrounds5m 50s
-
(Locked)
-
-
-