UITextField text property should be a non-optional String

Originator:PaulSolt
Number:rdar://46580238 Date Originated:12-9-18
Status:Open Resolved:
Product:iOS + SDK Product Version:Xcode 10.1
Classification:Bug Reproducible:Always
 
It doesn't make sense that the UITextField.text attribute is a `String?`.

    let newRange = Range(range, in: textField.text!)

It should be non-optional, because even when you set it to `nil` it's reverted back to "".

Why?

It makes programming with UITextField's confusing to developers.

A developers first experience with Swift is that there's a ton of optionals ... and there isn't a good best practice to avoiding them ... especially when they're completely unnecessary.

Should I unwrap it? Can it ever be nil?

I'm not really sure, but I'm pretty sure it can't, so I force unwrap the value to work with it, which is annoying.

Discussion: https://stackoverflow.com/questions/42861115/why-is-uitextfield-text-an-optional

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!