WWDC23 SALE: Save 50% on all my Swift books and bundles! >>

Variadic parameter in Day 11 Test (Access Control)

Forums > 100 Days of SwiftUI

I was surprised to see String... in Day 11's test:

struct School {
    var staffNames: [String]
    private var studentNames: [String]
    init(staff: String...) {
        self.staffNames = staff
        self.studentNames = [String]()
    }
}
let royalHigh = School(staff: "Mrs Hughes")

So I did some searching and eventually found that it is a Variadic parameter. The Swift language documentation says Int... can be treated like [Int] so I assume String... can be thought of as [String]

3      

Kind of but you can enter the elements with just a ,

let royalHigh = School(staff: "Mrs Hughes", "Mr White", "Miss Scarlet", "Prof Green")

Check this How to make a variadic function Also new in Swift 5.4 Multiple variadic parameters in functions

2      

Thanks @NigelGee

1      

Save 50% in my WWDC23 sale.

SAVE 50% To celebrate WWDC23, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.