Reputation: 5673
I'm trying to create an array of a simple struct using a range. What's the proper way to do it?
struct Stock {
var id = UUID()
var name: String = ["MSFT", "AAPL", "TSLA", "GOOG", "AMZN", "FB"].randomElement()!
}
//Generates the error: "Type of expression is ambiguous without more context"
var companies = (1...100).map { Stock() }
I'm on Swift 5.2 and Xcode 12.
Upvotes: 0
Views: 108
Reputation: 100541
You need to add _ in
as you don't use $0
inside the block
var companies = (1...100).map { _ in Stock() }
Upvotes: 1