Is there a nicer way to do a ‘lazy let’ property in Swift other than these 7 lines? I can’t see how to do this with property wrappers.
- It needs to be lazy because of the cyclic dependency with self.
- I know it’s not thread safe. This is UI so it’s fine.
- In practice I’d stick with var and hopefully remember not to set it.
6 hours later: The ideal case would be if this ‘just worked’. The language has syntax for expressing lazy let but the compiler doesn’t like it for some reason.
1 day later: Outcome of lazy let:
- You can do it with a property wrapper. (gist.github.com/douglashill/accde7f3db06b33a37f1389e32d293b1)
- It doesn‘t work for me because the property initialiser (closure capture) runs before self is available. The reason for using lazy was to break this cyclic dependency.