Programming in Swift: Fundamentals

Oct 19 2021 · Swift 5.5, iOS 15, Xcode 13

Part 5: Functions & Named Types

39. Challenge: Structures

Episode complete

Play next episode

About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 38. Structures Next episode: 40. Classes

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 39. Challenge: Structures

Update Notes: The student materials have been reviewed and are updated as of October 2021.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Okay. It's time for some practice with structures. Now you can find the challenge in the zero six challenge structures page of the playground you've been using all along or like always you can download a fresh one from the resources for this video. So open it up and try solving the challenge questions on your own first but as always keep watching and you can compare your solutions to mine. Good luck. (upbeat music playing) (upbeat music playing) (upbeat music playing) (upbeat music playing) On to challenge one. Create a structure named student with three properties. Okay. So the first task is pretty clear. I'm going to make a new student struct. And then I'll add the first name and last name properties, and I'll make them both strings, and I'll use an ENT for the grade. Okay. That's pretty good. So number two, create a structure named classroom with two properties. Okay. So let's go make a classroom struct. So this one needs a subject, again a string, and then a student array. So number three, create a method that returns the highest grade in the classroom. Okay. So this is going to belong to classroom. I'll call it a get highest grade. And I'm going to have it returned an optional ENT because if students was an empty array, there would be no highest grade. Now there are a few ways you might go about getting the highest grade, but I'm going to collect all the grades into a new array and then just return the highest value from that array. So to start, I need an EPI grades array. And then I'm going to use a four loop to iterate over the students and add the grades to the grades array. So finally, since this array is now populated with all the grades I can use the MAX method to pick out the highest one. There, on to challenge number two. So create an instance of a classroom. Okay. So I need to put some students' names and grades in there. Okay. So first I'll make an instance of a classroom with Catie, me, and Salvador Dali as students. So now I can use the get highest grade method to pull out the highest grade. So with a 75, I didn't get the highest grade but my clock designs were still fairly usable and they didn't melt but at least they told the right time twice a day.