0

NOTE: I know that this question is quite similar to others and I've tested all the answers but they just don't seem to work for me. That is why I'm posting this here.

My code:

var time = 10
var day = time * 86400
var week = day * 7

The error is:
Cannot use instance member 'time' within property initializer; property initializers run before 'self' is available

It points at 'time' in the day-variable.
I've tried:

lazy var day = time * 86400

But that doesn't change a lot.

var time:Double = 10
var day: [Double] {
    return [(time * 1440) as Double]
}
var week: [Double] {
    return [(day) * 7.0 as Double]
}

But then the error is:
Binary operator '*' cannot be applied to operands of type '[Double]' and 'Double'

Changing it to

var week: [Double] {
        return [(day) * 7.0 as [Double]]
    }

Doesn't work, error:
No '*' candidates produce the expected contextual result type '[Double]'

I just hope someone knows how to solve this :) Thanks!

G Buis
  • 303
  • 4
  • 17
  • `lazy var day: Int = self.time * 86400`, as demonstrated in [How to initialize properties that depend on each other](http://stackoverflow.com/questions/25854300/how-to-initialize-properties-that-depend-on-each-other). – Martin R Mar 24 '17 at 12:17
  • Your other approaches don't compile because `[Double]` is an "**array** of double" – Martin R Mar 24 '17 at 12:18
  • No errors in the code now, thank you! This worked! – G Buis Mar 24 '17 at 13:30

0 Answers0