Swift's property initializers can't reference other properties.
struct S {
let a = 0
let b = a // ❌
}
error: cannot use instance member a within property initializer; property initializers run before self is available
This is one approach to trying to prevent circular definitions like this:
struct S {
let a = b
let b = a //❓what would these values even be?
}
Some languages like Java take a more tolerant approach, by letting a member reference any members above it (i.e. on a line above it), forming a directed acyclic graph of interconnected member definitions.
Swift takes a stricter approach, and bans it outright. To get around this, you can:
Move your minDelay variable to a different place.
- Make it a static member
- Make it a static member of a different type (e.g. a
FooConstants case-less enum).
- Move it to a global variable (don't do this)
Make it a lazy var, as you said
- Set its value in an initializer, where the order of assignments is explicitly expressed.