From the course: Swift 5 Essential Training
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Solution: Battle actions - Swift Tutorial
From the course: Swift 5 Essential Training
Solution: Battle actions
(upbeat music) - [Instructor] All right, let's dive into our last challenge solution here and handle some errors. Our first task is going to be to create an enum that adopts the error protocol and has three cases. I'm going to say enum, I'm going to call this action error, It's going to adopt the air protocol, and for the first case, I'm going to say insufficient MP, second case out of range and third case unknown error. The second task we need to create a function, that's going to take in an integer and a double and return an optional Boolean. I'm going to say func attack enemy, parameter name is going to be MP for the first one and distance as a double. I'm also going to kick back an optional Boolean. And task three is pretty simple, we're going to mark attack enemy as a throw bool function with the throws keyword. For task number four, we need to add two guard statements to make sure that our MP and distance parameters…
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)
Final stage, final boss31s
-
(Locked)
Swift enumerations3m 57s
-
(Locked)
Raw and associated values5m 53s
-
Introducing protocols5m 55s
-
(Locked)
Using extensions4m 31s
-
(Locked)
Throwing errors3m 18s
-
(Locked)
Handling errors7m 12s
-
(Locked)
Challenge: Battle actions39s
-
(Locked)
Solution: Battle actions4m 41s
-
(Locked)
-