问题
My class declares an array
var laps: (start: NSDate!, end: NSDate!)[] = []
When a tuple is added to this array I'd like to be able to do something like
let now = NSDate()
var lap = (now, nil)
laps.append(lap)
But at the append I get the error Missing argument for parameter 'end' in call.
回答1:
I've tried to following, and it looked correct syntactically:
typealias MyTuple = (start: NSDate!, end: NSDate?)
then in the method, I did:
var laps: Array<MyTuple> = Array()
laps.append((NSDate.date(), nil))
回答2:
There's a bug in using .append with arrays of tuples. You can use the += operator instead:
laps += lap
来源:https://stackoverflow.com/questions/24575331/appending-tuples-to-an-array-of-tuples