Appending tuples to an array of tuples

后端 未结 2 711
轮回少年
轮回少年 2020-12-20 00:12

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 s

相关标签:
2条回答
  • There's a bug in using .append with arrays of tuples. You can use the += operator instead:

    laps += lap
    
    0 讨论(0)
  • 2020-12-20 01:16

    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))
    
    0 讨论(0)
提交回复
热议问题