user190494
user190494

Reputation: 509

While trying to change placeholder text, fatal error: unexpectedly found nil while unwrapping an Optional value

I am trying to modify the placeholder text of a text field in Swift. However there is an error about "fatal error: unexpectedly found nil while unwrapping an Optional value." I am not sure why this would be nil.

enter image description here

Thanks!

Upvotes: 0

Views: 578

Answers (2)

mt81
mt81

Reputation: 3318

Since you have weak pointer I think you should use ? and use it again to unwrap your variable.

@IBOutlet weak var input: UITextField?

input?.placeholder = "some text";

But as someone already said, you probably haven't connected the IBOutlet.

Upvotes: 1

Rob Napier
Rob Napier

Reputation: 299455

input is UITextField!. It's probably nil, which probably means you forgot to connect it in Interface Builder.

Upvotes: 1

Related Questions