April 2026
Intermediate
683 pages
25h 29m
English
As you will remember from Chapter 5, functions are able to import, return, or modify variables. Likewise, functions can be used to import, return, or modify struct variables too. Although the syntax is not any different, we will present some examples to keep this chapter self-contained.
Listing 8.30 demonstrates a struct import example. Within the ClassRoom struct, there is a addStudent function, which accepts a Student instance as a parameter to append to its array of students. As stated, there’s nothing special about the syntax of the function; we’re merely demonstrating an example.
struct Student { let name: String}struct ClassRoom { private var students: [Student] = [] mutating func addStudent(_ student: ...
Read now
Unlock full access