Tharnatoz Tharnatoz - 3 months ago 5x
Swift Question

UITextView.text can't take a variable of type String?

There are very confusion things going on...

I try to set a text from the UITextView via

UITextView.text = myVar
but this won't work, every time i run this code this exception is shown:

fatal error: unexpectedly found nil while unwrapping an Optional value

@IBOutlet weak var myTextView: UITextView!

let myStringVar: String = "I am a test string"

myTextView.text = myStringVar

But this peace of code works very well:

@IBOutlet weak var myTextView: UITextView!

myTextView.text = "I am a test string"

Why is that so? Can anyone help me?


insert print(myTextView) before myTextView.text = myStringVar and check, if myTextView not nil.