10

Implicitly unwrapped optionals are a useful feature of Swift for things like UI elements that are not assigned during a class's constructor, but can be safely be assumed to be non-null for the majority of functions (as they will have been assigned in a viewDidLoad).

eg.

@IBOutlet weak var textView : UITextView! 

Is there an equivalent for Kotlin, or a workaround that achieves the same effect?

stantronic
  • 397
  • 7
  • 14

1 Answers1

20

lateinit var may be a suitable solution. Kotlin just assumes they are not null. https://kotlinlang.org/docs/reference/properties.html#late-initialized-properties

Miha_x64
  • 5,973
  • 1
  • 41
  • 63