The compiler gets confused because it doesn't know the type of the optional NSDate
. You can let it know explicitly about the type.
let items : Array<(Int, Int, Int, String, NSDate?)> = [
(1, 9, 7, "A", nil),
(2, 9, 7, "B", mydate),
(3, 9, 7, "C", mydate),
(4, 9, 7, "D", mydate)
]
Edit: For the problem with using instance variable, you could initialise your items with a closure.
let items : Array<(Int, Int, Int, String, NSDate?)> = {
let mydate = NSDate()
return [
(1, 9, 7, "A", nil),
(2, 9, 7, "B", mydate),
(3, 9, 7, "C", mydate),
(4, 9, 7, "D", mydate)
]
}()