0
0
Swiftprogramming~15 mins

Array creation and type inference in Swift - Mini Project: Build & Apply

Choose your learning style9 modes available
Array creation and type inference
📖 Scenario: You are organizing a small party and want to keep track of the guests' names using an array.
🎯 Goal: Create an array of guest names using Swift's type inference and then print the list.
📋 What You'll Learn
Create an array called guestNames with exactly these names: "Anna", "Brian", "Catherine"
Create a variable called newGuest and assign it the value "David"
Add newGuest to the guestNames array
Print the guestNames array
💡 Why This Matters
🌍 Real World
Arrays are used to store lists of items like guest names, product lists, or scores in many apps.
💼 Career
Understanding arrays and type inference is essential for Swift developers building iOS apps that manage collections of data.
Progress0 / 4 steps
1
Create the initial array
Create an array called guestNames with these exact names: "Anna", "Brian", "Catherine". Use Swift's type inference by not specifying the type explicitly.
Swift
Need a hint?

Use square brackets to create an array and assign it to guestNames.

2
Add a new guest variable
Create a variable called newGuest and assign it the value "David".
Swift
Need a hint?

Use var newGuest = "David" to create the variable.

3
Add the new guest to the array
Add the newGuest variable to the guestNames array using the append method.
Swift
Need a hint?

Use guestNames.append(newGuest) to add the new guest.

4
Print the guest list
Print the guestNames array to show all guest names.
Swift
Need a hint?

Use print(guestNames) to display the array.