import Foundation
struct locus { var x: Int var y: Int }
let aerodrome: [locus] = [(1,1), (2,2)]
produces error "Cannot convert value of type '(Int, Int)' to expected element type 'locus'" I love that the compiler accepts 'locus' as a type - I hate that it doesn't accept the Ints I try and input. Help appreciated.
Your literal
[(1,1), (2,2)]is an array of tuples. Try:in the playground and option-click
aerodromeand you'll get:If you want an array of
locusyou need to create instances of them. One way to do this is to use the automatic default constructor which requires named arguments:If you don't wish to use the labels write your own
init.